Menu
  • HOME
  • TAGS

syntax error : missing ')' before 'constant'

c,compiler-errors,macros,syntax-error,c-preprocessor

#define is a preprocessor MACRO which acts as a textual replacement in the preprocesssing stage. In your case, with a MACRO like #define N 10 and then with a function like void displayMatrix(int *arr,int M, int N); it turns out to be void displayMatrix(int *arr,int M, int 10); //note the...

Accessing argument's metadata in Clojure macro

clojure,macros

I ended up finding a solution: (def ^{:a :b} my-var) (defmacro my-macro [s] (prn (meta (resolve s)))) (my-macro my-var) ;; Prints {:a :b, :name my-var, ...} So the key part here is to use resolve function to get the var associated to the symbol....

how to apply macro on list of lines with vim

linux,vim,macros

If those lines have something in common, you can use the :global and :normal commands: :g/foo/norm! @1 which is slightly "smarter" but probably a bit less intuitive than: [email protected] [email protected] [email protected] See :help :global and :help :normal....

AutoHotKey macro scripting to open Outlook and create appointment

macros,autohotkey

It is not particularly robust or elegant but the code below works well on my machine. Have outlook running open to inbox without other outlook windows present for testing. Pressing 'window + u' will first look for an approximate window match (you can also use ahk_class) and send keystrokes to...

Advantages of do { } while(0) versus ({ }) in a macro?

c,macros

Because ({...}) is a GCC extension.

use definitions in loop (c coding)

c,arrays,for-loop,macros

If you change #define COLUMN3 'a' #define COLUMN4 'b' and use like int col[4]={COLUMN1, COLUMN2, COLUMN3, COLUMN4}; for (int var = 0; var < 4; ++var) { if(col[var]) { .... ; // var //do something } } you should be syntactically okay....

How to create a nnkUInt16Lit NimNode

macros,nim

This should work: var n = parseExpr "1'u16" With this pull request your original code will work as well: https://github.com/Araq/Nim/pull/2754...

clojure quoting inside let

clojure,macros,eval

Kevin You were close, this should do the work (basically, you should unquote the local var in the quoted statement) (let [foo 1] (eval `(print ~foo))) Also, while eval is certainly a valid language function, what is the overall goal? There may be better ways altogether. Frank...

How to control C Macro Precedence

c,macros

You can redirect the JOIN operation to another macro, which then does the actual pasting, in order to enforce expansion of its arguments: #define VAL1CHK 20 #define NUM 1 #define JOIN1(A, B, C) A##B##C #define JOIN(A, B, C) JOIN1(A, B, C) int x = JOIN(VAL,NUM,CHK); This technique is often used...

C++ / C #define macro calculation

c++,c,macros

Are DETUNE1 and DETUNE2 calculated every time it is called? Very unlikely. Because you are calling sqrt with constants, most compilers would optimize the call to the sqrt functions and replace it with a constant value. GCC does that at -O1. So does clang. (See live). In the general...

Understanding NASM Macro

assembly,macros,ffmpeg,nasm

The DEFINE_ARGS macro defines a number single line macros the are meant to be used to refer to the arguments of the function that the cglobal macro introduces. So for example, if foo is given as the name of the first argument then DEFINE_ARGS creates the following defines: %xdefine fooq...

Julia: How do I create a macro that returns its argument?

macros,julia-lang

The input expression to the macro needs to be quoted because a macro returns an expression, which are evaluated, while you would like to get the expression itself, hence you need an extra quoting. The quoting can be done as: macro mymacro(ex) Expr(:quote,ex) # this creates an expression that looks...

Macro to push arguments onto stack

visual-c++,assembly,macros

If you are still interested in tricking the Visual C++ compiler you can try this code #define pushargs(...) for (unsigned int _esp; ;) _esp = varcount(), _esp =(_esp-varcount(__VA_ARGS__))>>2, pushargs_c(_esp, __VA_ARGS__ ); unsigned int __declspec(naked) __forceinline varcount(...) { __asm mov eax, esp; __asm ret; } unsigned int __declspec(naked) __forceinline pushargs_c(unsigned int...

How can I change the value stored in local macro from string to numeric in Stata?

types,macros,global,local,stata

If you add =, then Stata will evaluate the expression that defines local date: clear set more off set obs 10 gen y_passed = _n local date = substr("$S_DATE",8,.) display `date' gen start_year = `date' - y_passed list Otherwise, the local just holds a string, but not a number in...

Combining multiple template classes to one class using typedef

c++,templates,macros,typedef

In my own code I also separate the declaration from the implementation. Sometimes I just need the code to know that there exists a template, more often I want to make it very easy to see what the interfaces are. I have solved this tedious typing with macros. However, the...

What does the non-terminating-p argument of set-macro-character do?

macros,common-lisp

If you set non-terminating-p to t the macro character can appear unescaped within a symbol name (like # in the symbol foo#baz). If you leave it nil and the reader encounters the macro character while accumulating a symbol it terminates the collection of the symbol (like ' in foo'bar, which...

Defining Macros that are equal to functions that return objects in C++

c++,static,macros,singleton

The problem is that you defined TheUniverse as Universe::GetInstance();, with a semicolon. Therefore, after macros are processed, you get Universe::GetInstance();.Initialize(); which is obviously not what you want. To fix the problem simply remove the semicolon in the macro definition.

Read input into string in Lisp reader macro

macros,common-lisp,reader-macro

You can try to use read and then look at what it returns: (defun string-reader (stream char) (declare (ignore char)) (let ((this (let ((*readtable* (copy-readtable))) (setf (readtable-case *readtable*) :preserve) (read stream t nil t)))) (etypecase this (string this) (symbol (symbol-name this))))) (set-macro-character #\@ #'string-reader) Above would allow @This and @"This",...

Can I create a macro that unrolls loops?

macros,rust

Well, sort of. macro_rules! unroll { (0, |$i:ident| $s:stmt) => {}; (1, |$i:ident| $s:stmt) => {{ let $i: usize = 0; $s; }}; (2, |$i:ident| $s:stmt) => {{ unroll!(1, |$i| $s); let $i: usize = 1; $s; }}; (3, |$i:ident| $s:stmt) => {{ unroll!(2, |$i| $s); let $i: usize =...

Is there a Visual Studio Project Configuration Macro which defines DEBUG or RELEASE regardless of the Project Configuration Name?

visual-studio,visual-c++,visual-studio-2013,configuration,macros

Property sheets allow you to make 'User Defined Macros', which translate into configuration variables you can use in your project files. You would: Create a two property sheets. In each, create a User Defined Macro (named say ConfigurationType - do not use $ or () when creating it), in one...

macro for switching between auto_ptr and unique_ptr

c++,c++11,macros,unique-ptr

For just nullptr and unique_ptr, this could work: #ifndef HAVE_CXX11 #define nullptr NULL #define unique_ptr auto_ptr #endif But I don't know how you plan to cope with the different semantics of unique_ptr and auto_ptr. If you're willing to live with some undefined behaviour for a while (of the kind unlikely...

Is there any way to skip macro replacement(During preprocessing) when macro is used as a variable name?

c++,qt,c++11,macros,qt5

You should be able to fix that problem by using: #include "ConflictHeader.h"//Include conflicted header #ifdef _c #undef _c #endif A better option might be to create a wrapper .h file fro ConflictHeader.h and use the wrappr .h file in rest of your code. ConflictHeaderW.h: #pragma once #include "ConflictHeader.h" #ifdef _c...

Use Weka from ImageJ macro: 'path' is required but unset

macros,weka,imagej

The Trainable Weka Segmentation plugin doesn't adhere to the macro recording conventions of ImageJ, mainly because of its complex structure. However, the correct way to interact with the plugin by macro scripting is described extensively in its documentation on the Fiji wiki. In summary, you need to something like: open("C:\\input\\test.tif");...

Can macros expand to a combination of patterns?

macros,pattern-matching,rust

A macro is able to expand to things like patterns, expressions and items, but not everything; specifically, macros expand to complete AST nodes, but what you’re dealing with here is not a complete AST node. Each branch of a match expression can have one or more patterns, separated by pipes,...

How to use a parameter in a macro call?

macros,lisp,common-lisp,sbcl

I would use something like this: CL-USER 86 > (defmacro define-class (class-name) `(defclass ,class-name ()())) DEFINE-CLASS CL-USER 87 > (defun create-data (mode) (funcall (compile nil `(lambda () (define-class ,mode))))) CREATE-DATA CL-USER 88 > (create-data 'bar) #<STANDARD-CLASS BAR 402016CC73> Above uses code generation and the built-in compiler....

Can somebody explain this weird error in pig

hadoop,macros,apache-pig,hadoop2

We can NOT assign one alias directly to another. We can project the required fields from one alias and return the same. For the use case shared : $result_metric = FOREACH result_1 GENERATE *; This step is not required unless there is a change in projected fields between these two...

create a macro in sas

macros,sas

proc summary allows you to control exactly which ways you want to cross the data. %macro report(year); proc import datafile="/path/to/report-&year..xls" out= salary_data dbms=csv replace ; proc summary data = salary_data; class married gender; types married gender married*gender; var sal; output out = salary_results mean(sal) = mean_salary std(sal) = std_salary; *...

Introducing variables named by user in a macro

scala,macros,scala-macros

It's impossible to do this in a def macro, because def macros require all their arguments to typecheck prior to expansion. Macro annotations don't have this restriction, but they have different syntax that might be inappropriate for your use case.

macro error: A character operand was found in the %EVAL function or %IF condition

macros,sas,sas-macro

The macro %IF statement implicitly calls the %EVAL() function. %EVAL() understands integers (whether positive or negative), but not decimal values. When %EVAL() compares two values, if one of them is a decimal it will do a CHARACTER comparison. So %IF (3.1>10) returns true. If you give %EVAL a decimal with...

Stata- Stopping at the variable before a specified variable in a varlist

macros,stata

Here's one approach building on your code. . sysuse auto.dta, clear (1978 Automobile Data) . quiet describe, varlist . local vars `r(varlist)' . display "vars - `vars'" vars - make price mpg rep78 headroom trunk weight length turn displacement gear_ratio foreign . lookfor "Circle" storage display value variable name type...

How to share same header files between kernel modules and userspace applications.

linux-kernel,macros,linux-device-driver,header-files,ioctl

The _IO and _IOWR (and so forth) macros are also available in user-space headers. The definitions can be pulled into both kernel-space and user-space source by #including <linux/ioctl.h> first. You should separate your kernel header files into two parts: (a) those needed only by the kernel code -- struct definitions,...

What is the difference between executing a macro and executing the contained instructions within it in Teradata?

macros,teradata

A Macro is exactly the same as a MultiStatement Request (MSR). When you EXPLAIN EXEC mymacro you will notice that all the statements within the macro are done followed by a final END TRANSACTION step. Now if you do something like a DELETE ALL as a standalone transaction it's a...

Get the ith word in a macro variable list

macros,sas

The short answer is to use the %scan function: %put %scan(&tablelist,4,%str( )); The third argument specifies that %scan should count only spaces as delimiters. Otherwise, it will also treat all of the following characters as delimiters by default: . < ( + & ! $ * ) ; ^ -...

error when vim macro recording play

vim,macros

You should include the movement command (probably j in your case) in the macro. So record your macro as qaI#Escjq And then play it with [email protected]

nasm, macro print not working

c,assembly,macros

According to standard calling convention, some registers are caller-saved, namely eax, ecx and edx. As such, you shouldn't expect their value to be retained through a call printf. That's presumably why you get wrong value printed. You could push the second one on the stack before printing the first one,...

Average in assembly 8086 (macro error)

assembly,macros,average,8086

I tested your code in EMU8086, and this is the solution that worked for me, next is your data segment with 5 little changes : data segment sum dw 0 ;<========================== dw 0 ;<========================== num dw 0 ;<========================== dw 0 ;<========================== msg1 db 'Enter 20 numbers:', '$' msg2 db 0dh,0ah,'Average:...

Extract Argument from C Macro

c,macros,arguments,c-preprocessor

Do not use macros for this. If you must, the following will work by throwing away the left part first so just the number remains. Use with care. No guarantees. #define PIN_ALARM GPIOC,14 #define RIGHTPART_ONLY(a,b) b #define PIN_MODE_OUTPUT(a) RIGHTPART_ONLY(a) #define RESULT PIN_MODE_OUTPUT(PIN_ALARM) int main (void) { printf ("we'll pick ......

How do you replace the first and last line in Notepad++?

macros,notepad++

A single regular expression replace can do this. To delete the first and last lines: Select Dot matches newline, select Wrap around and set the Find what to be \`[^\r\n]*[\r\n]+(.*[\r\n]+)[^\r\n]+[\r\n]*\' Set the replace with to be \1 My testing has sometimes required Find next to be pressed twice. The first...

c++ concatenating macro definitions

c++,macros,concatenation,preprocessor

Yes, you can concatenate macro replacements with the ## preprocessor directive and some auxiliary quoting macros. #define _LOAD _mm256_load #define _FLOAT ps #define CAT(X, Y, Z) X ## Y ## Z #define CMB(A, B) CAT(A, _, B) #define FOO CMB(_LOAD, _FLOAT) Now use FOO, or just CMB(_LOAD, _FLOAT) directly....

Defining macro function from makefile

c++,c,makefile,macros

You can insert a header from the command line to all sources by adding this to the CXX flags: -include "path/to/header.h" EDIT: In your particular case you could also pass this to the CXX flags to make a macro function: -D'dbg_print(...)=printf(__VA_ARGS__)' on windows it worked for me with " and...

Need to fix my Variadic Macros

c++,c++11,macros,variadic-macro

Remove the extra ##, as in replace the lines sv. ## ServerFunction ## (ssl, arg1, arg2, arg3); \ with sv. ServerFunction (ssl, arg1, arg2, arg3); \ EDIT Can you try to compile the following code? #include <string> #define SERVER_RE_1(ServerFunction, Type1) \ { \ Type1 arg1; \ getData(args, arg1); \ sv....

defining recursive values C

c,macros

The first is a macro with one parameter. When the pre-processor sees BLOCK_OFFSET(...) then it is replaced by (BASE_OFFSET+(...-1)*block_size) #define BLOCK_OFFSET(block) (BASE_OFFSET+(block-1)*block_size) The second is a usage of the macro as described above: Before pre-processing: lseek(fd, BLOCK_OFFSET(group->bg_inode_table)+(inode_no-1)*sizeof(struct ext2_inode),SEEK_SET); After pre-processing: lseek(fd, (BASE_OFFSET+(group->bg_inode_table-1)*block_size)+(inode_no-1)*sizeof(struct ext2_inode),SEEK_SET); If you use gcc you could use...

Split string in macro

c++,string,split,macros

You can just change your macros so that it will accept two parameters: the namespace name and the class name. Something like #define BASICTYPE_TRAITS(namespaceName, className) \ template <> \ struct DDSTraits<namespaceName::className> \ { \ using TypeSupportImpl = namespaceName::className##Impl; \ using TypeSupport_var = namespaceName::className##TypeSupport; \ }; template <typename T> struct BASICTYPE_TRAITS...

Macro that defines functions whose names are based on the macro's arguments

macros,common-lisp,symbols,sbcl

That's a usual problem: what gets passed to a Macro? Compare calls like this: (symb 'book '-p) and (symb ''book '-p) Your macro form is this: (gen-predicate 'book) GEN-PREDICATE is a macro. classname is a parameter for this macro. Now what is the value of classname inside the macro during...

Too many warnings on a C macro

c,gcc,macros,warnings

Regarding the warnings listed in your edit: unknown conversion type character ‘,’ in format This ... "Invalid Position at (%l, %l, %l)", ... should be ... "Invalid Position at (%ld, %ld, %ld)", ... You pass long signed int. The conversion specifier for signed int is d. When passing long prefix...

Parentheses and macro overloading in C++

c++,macros

Macro overloading is not possible. In your case since you don't want SOME_MACRO anymore once the SOME_MACRO(...) is defined, you may do following in the intended (header) file: #undef SOME_MACRO // hopefully it is not a standard macro! #define SOME_MACRO(...) // use __VA_ARGS__ Now in the code you can call...

Creating a function in compile time using a bitmap like macro

c,macros

The way I would do it would be with a macro that defined all the patterns you want, combined with other macros that defined the functions or other info you need about them. So you would have something like: #define FUNCTION_PATTERNS(M) \ M(1, 0xf) \ M(2, 0x3) \ M(3, 0x9)...

Expanded from macro 'num' while printing it using printf by Clang compiler

c,gcc,macros,clang,c-preprocessor

It is probably complaining that the expression expanded from color_num is an unsigned (perhaps unsigned long) while the format in the printf is a signed integer. sizeof gives size_t, which is always an unsigned type, as noted in is size_t always unsigned?, but the number of bits depends on the...

%mend statement in SAS macro

macros,sas

Practically, there is no difference, you can use any of the two. But as a good programming practice you should use first one as it helps in identifying where the macro ends. If you are using the first one, just remember to put the same name after mend that you...

Can I create a macro or shortuct for a step of XPath in XQuery?

xml,xpath,macros,xquery

XQuery does not know such macros, you could of course use any preprocessor to do such things. But I'd rather define a function for this: declare function local:outward($context as item()) { $context/ancestor-or-self::* }; Functions can also be applied in axis steps (remember to pass the current context .): let $xml...

Macro for defining trait aliases

macros,rust

expr is an expression token tree, which clearly doesn’t fit in the locations you have tried to place it. Remember that Rust macros are strongly typed: only the types of token trees expected at a given location are permitted. You’ll need to use sequence repetition ($(…)* et al.) of ident...

How to write an ipython alias which executes in python instead of shell?

python,macros,ipython,alias,ipython-magic

The normal way to do this would be to simply write a python function, with a def. But if you want to alias a statement, rather than a function call, then it's actually a bit tricky. You can achieve this by writing a custom magic function. Here is an example,...

Importing a common constant declared pig file in other pig files

import,macros,apache-pig

The IMPORT keyword is used to import macros, not constants. %declare and %default are preprocessor statements, and its scope is all the remaining lines in the script. If you declare it in a script, but import it from a different one, it will not work because it is out of...

How to determine macro value at compilation time in C?

c,compilation,macros,cc

C compilers allow macros to be defined on the command line, usually with the -D command line option: This defines the macro SIGDET to the value 1. gcc -DSIGDET myprogram.c You can specify the value this way: gcc -DSIGDET=42 myprogram.c You can even define the macro as empty: gcc -DSIGDET=...

Wrong macros definition casuses “Expected expression” error

c,macros

You defined FALSE to be 0;, define it to be 0 (#define FALSE 0, without a semicolon). The semicolon is included in the define, so FALSE gets replaced with 0; which puts a semicolon in your if conditional.

Why is my C code printing out an extra line of rows?

c,loops,for-loop,macros,printf

There is no issue with the #define, there is one issue with the conditional statement in the for loop. I believe, you'er overlooking the <= operator. You need to have only < operator. Change for(i=0;i<=rows;++i) to for(i=0;i<rows;++i) That said, the recommended signature of main() is int main(void)....

Scheme define-macro and/or define-syntax

macros,polymorphism,scheme,overloading

I think that Chris is right in that this is not really a job for macros. A simple procedure might be what you're looking for: (define (lookup key container) (cond ((type1? container) (type1-lookup key container)) . ; repeat for whichever types.. . ((typeN? container) (typeN-lookup key container)) (else 'undefined-lookup))) ;...

Why is it not advised to define macros in header files?

c++,macros,preprocessor

The preprocessor concatenates all included source files together in order. If you don't undefine a macro, it can apply to any source following where it was first defined. Since headers are often the public API of a library, any macros you define in your headers could end up in someone...

How does this code print odd and even?

c,if-statement,macros,logic

In binary any numbers LSB (Least Significant Bit) is set or 1 means the number is odd, and LSB 0 means the number is even. Lets take a look: Decimal binary 1 001 (odd) 2 010 (even) 3 011 (odd) 4 100 (even) 5 101 (odd) SO, the following line...

Statement in C++ macro

c++,c,macros,c-preprocessor

This macro uses the Statement-Expressions GCC extension. The last expression in the inner block serves as the value for the whole, once it has been executed, much like the comma operator.

Python-like C++ decorators

python,c++,function,macros,decorator

std::function provides most of the building blocks for my proposed solution. Here is my proposed solution. #include <iostream> #include <functional> //------------------------------- // BEGIN decorator implementation //------------------------------- template <class> struct Decorator; template <class R, class... Args> struct Decorator<R(Args ...)> { Decorator(std::function<R(Args ...)> f) : f_(f) {} R operator()(Args ... args) {...

Dose VS2010 pre-calculate preprocessor defined by #define?

c++,visual-studio-2010,macros,preprocessor

the #define will do a direct text replacement. Because of that everywhere you have PI it will get replaced with 4.0f*atan(1.0f). I would suspect the compiler would optimize this away during code generation but the only real way to know is to compile it and check the assembly. I found...

Append the string provided by __FUNCTION__ macro

c++,macros

You can add an additional macro #define STRINGIZE(str) #str and use it like this: ADD_TIME_ENTRY(__FUNCTION__ STRINGIZE(start)) Seems like __FUNCTION__ might be not a macro so it is not particularly easy to combine it with anything in such a case. In MSVC2013 it is a macro so it is easy combinable....

Backquote String Interpolation

macros,lisp,common-lisp

Lisp macros operate on arguments that have already been read by lisp's reader. Because of that a macro can't change how it's arguments are read, and if you pass an argument that will signal an error when you try to read it, e.g. 9:00 in (test 9:00), the reader signals...

In which situation does this macro can cause an error?

c,macros,preprocessor,c-preprocessor

in the case that its argument has side effects when evaluated. For example, SQ(i++) is undefined behaviour.

Is that possible to get comments with macro?

macros,elixir

No, you cannot get code comments inside macros. They never become part of the AST and are discarded still in Elixir's tokenizer.

Why do I have to expose a macro implementation's 'use' in the client library?

macros,rust

Because macro_rules! is a bit dumber than you might expect. It does not, for example, bring imports with it when it expands something. It's best to think of macro expansion as mostly just a dumb copy+paste job. If you look at any reasonably well-written macro that depends on outside symbols,...

call a function from a header file

c,function,macros,header

Why not just have a initializer function? Normally, you will not use many global variables, so that would not be much of a problem. And for local variables, you'd need that anyways. For the original question: A macro is just a text replacement. It is performed before the C compiler...

type of expanded C macro

c,macros,petsc

It's simple text substitution, so you end up with: extern PETSC_VISIBILITY_PUBLIC MPI_Comm PETSC_COMM_WORLD; Hence the type of PETSC_COMM_WORLD is PETSC_VISIBILITY_PUBLIC MPI_Comm and so depends on the definition of PETSC_VISIBILITY_PUBLIC, which hasn't been provided. From a cursory search of the net, it will be empty when building the petsc DLL or...

Expand define macro with include macro

c++,c,macros,include

This can't be done. The resulting completely macro-replaced preprocessing token sequence is not processed as a preprocessing directive even if it resembles one, [...] That particular quote is from a reasonably recent draft of the C++ standard, but with minor changes in wording, the same basic idea has been around...

Providing new version of existing macro with parameters

c++,macros,overloading

You may change your macro to return an object with operator ()(const std::string&), something like: struct Logger2 { explicit Logger2(const std::string& name) : name(name) {} Logger2& operator << (const std::pair<const char*, const char*>& p) { std::cout << name << ":" << p.first << " " << p.second << std::endl; return...

Assigning UIColor values to macros

ios,objective-c,macros,global-variables,uicolor

The key thing to understand in this context is that a preprocessor macro only replaces (really, 1-to-1 replaces) the code for the macro at compile time, thus your error-generating code actually looks like this to the compiler: self.view.backgroundColor = = [UIColor colorWithRed:(238.0f/255.0f) green:(251.0f/255.0f) blue:(255.0f/255.0f) alpha:0.8f]; You can see for yourself...

Writing a `define-let` macro, with hygiene

macros,racket,define-syntax,hygiene

Following the cue "syntax-parameter" from Chris, here is an one solution: #lang racket (require racket/stxparam (for-syntax syntax/strip-context)) (define-syntax (define-let stx1) (syntax-case stx1 () [(_ name [var expr] ...) (with-syntax ([(value ...) (generate-temporaries #'(expr ...))]) #`(begin (define-syntax-parameter var (syntax-rules ())) ... (define value expr) ... (define-syntax (name stx2) (syntax-case stx2 ()...

Can't forward parameters to nested macros

macros,rust

For this case, you can't use parentheses as grouping, you need to use them as part of your macro pattern. I'd avoid using parens to avoid this confusion. Here, I changed your macro a bit to accept zero-or-more sets of {}. You can macro-iterate over each of them and call...

C++ Macro Magic: getting for every macro parameter, the parameter count number

c++,macros

I found the answer myself: #define IT_CHOOSER2(name,count) name##count #define IT_CHOOSER1(name,count) IT_CHOOSER2(name,count) #define IT_CHOOSER(name,count) IT_CHOOSER1(name,count) #define IT_SET_ARGS_PREFIX IT_SET_ARGS_ #define IT_SET_ARGS_1( foo, arg_1) kernel.setArg(0, arg_1) #define IT_SET_ARGS_2( foo, arg_1, arg_2) kernel.setArg(0, arg_1); kernel.setArg(1, arg_2) ... #define IT_SET_ARGS(foo,...)\ IT_GLUE(IT_CHOOSER(IT_SET_ARGS_PREFIX,IT_N_ARGS(__VA_ARGS__)), (kernel,__VA_ARGS__)) But i want to mention that Jarod42 solution is much...

clojure macro create || comparison?

clojure,macros

Clojure's equivalent of || is the macro or . You can view its implementation here. If you want to use the symbol ||, you can just alias the or macro: (def #^{:macro true} || #'or) You can then use either: (or (get a 0) (b)) or (|| (get a 0)...

Picking up a certain string pattern without regex

c++,regex,c++11,macros

The simplest way I can think of is using std::getline to read up to every open paren ( and then check that string for your macro. Then another std::getline to read up to the closing paren ) should extract your macro's parameters. A bit like this: const std::string EXTERNALIZE =...

Correct way to cast a gpointer to a GType

types,macros,glib,gnome

OK I seem to have figured it out myself now.... Firstly, I was using the wrong test in checking for GTYPE_TO_POINTER and GPOINTER_TO_GTYPE since they were the variables I wanted to define the compiler could not find them and the definition was never being made. Secondly, I was using undefined...

Why use max and min macro in __global__ kernel of CUDA not giving correct answer?

c++,cuda,macros

Getting rid of the (float) to clear the clutter, your macros look like this: #define min(a, b) (a > b)? b: a #define max(a, b) (a > b)? a: b And example use (simplifying a few variable names): imgx = min(max(x + aipx, 0), nc-1); will expand to: imgx =...

Unexpected output printf statement [duplicate]

c,macros,printf,ternary-operator

k==MAX(i++,++j); is translated to: k==(i++) > (++j) ? (i++) : (++j); /* 2 1 3 : Precedance */ In your case i = 10 and j = 5, so the comparision would be 10 v/s 6 which would be true or 1 with side effect i becomes 11 and j...

SAS Concatenate Multiple Variables to Create Data-Driven Macro Statements

sql,macros,sas,append,concatenation

Answered my own question. This does what I need: DATA TEST1; SET TEST; STRING=COMPRESS(%NRSTR("%APPEND""("||COMPRESS(YEAR)||","||COMPRESS(CONDITION)||","|| COMPRESS(QRTS)||","|| COMPRESS(SAMPLE)||")"),""""); RUN; %APPEND can then be replaced by any macro name created, so this could be very useful. ...

Why does this operation break when turned into a function (AutoHotKey/AHK)

function,com,macros,ms-office,autohotkey

You're calling return before the function can finish. This causes the script to stop processing that function and return to the caller. ReplaceAndLink(FindText, ReplaceWith) { ; Word Constants vbTrue := -1 wdReplaceNone := 0 wdFindContinue := 1 return <---------- HERE try oWord := ComObjActive("Word.Application") catch return Try removing that and...

How to test whether an identifier that is accessible only through a #define macro is defined?

c++,c,macros

Defining identifiers (functions, objects) is something that happens after the preprocessing, so you can not possibly determine during preprocessing whether a function will be defined later. What you can do as workaround is that you always define a macro alongside with the function: void A(); #define A_SUPPLIED and then test...

How to implement a runtime debug assertion without macros in C++ 11/14 with type safety?

c++,c++11,macros,assertion

The benefit of using macros for this purpose over functions is as you said, there is a chance that the check won't be completely optimised out and you'll still pay for the dynamic_cast. Your best option is to use assert(dynamic_cast<Derived*>(_ptr) != nullptr). Type safety doesn't buy you anything for assert-like...

C++: complex function-like macro definition

c++,node.js,macros

Let's run ONLY the processor over the following code: // Strings are per-isolate primitives but Environment proxies them // for the sake of convenience. #define PER_ISOLATE_STRING_PROPERTIES(V) \ V(address_string, "address") \ V(args_string, "args") \ V(argv_string, "argv") \ V(async, "async") \ #define V(PropertyName, StringValue) \ inline v8::Local<v8::String> PropertyName() const; PER_ISOLATE_STRING_PROPERTIES(V) #undef V...

x-macro conditional error - number comparison

c,macros,x-macros

Yes, here's a proof of concept: #pragma push_macro("X") #undef X #define X(a,b) typedef int x[(a>b)?-1:1]; LIST #pragma pop_macro("X") So, we define X to define a type of array of ints, with either -1 or 1, depending whether a is greater than b. If it is, the array of -1 elements...

doxygen misrendering macro type as public member function

c,macros,doxygen

From the Doxygen documentation EXPAND_ONLY_PREDEF If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES then the macro expansion is limited to the macros specified with the PREDEFINED and EXPAND_AS_DEFINED tags. The default value is: NO. This tag requires that the tag ENABLE_PREPROCESSING is set to YES. EXPAND_AS_DEFINED If...

Elisp: how to make this function short

emacs,macros,elisp

Untested: (require 'cl) (defun jst-remember-project-type (type &rest args) "Let JST remember another project type." (if (gethash type jst-known-project-types) (error "Redefined JST project type.""") (let ((table (make-hash-table :test #'equal))) (loop for (label value) on args by #'cddr do (puthash label value table)) (puthash type table jst-known-project-types)))) ...

Converting a case class to CSV in Scala

scala,csv,macros,case-class

How about implicits and productIterator? implicit class CSVWrapper(val prod: Product) extends AnyVal { def toCSV() = prod.productIterator.map{ case Some(value) => value case None => "" case rest => rest }.mkString(",") } Person("name", 30, "male", None).toCSV() ...

Do macros run faster than global variables in C? How to change macros between runs?

c,macros

Well, here's a potential source of the performance difference. With a macro, the value of CONSTANT is known at compile time, so the compiler can take advantage of that knowledge and structure the machine code a little differently. I took a variation of your code and used gcc -Wa,-aldh to...

Is it safe to use macros in R?

r,macros

Of course you have to be careful. Macros do not have their own environments. Simple example f(x,y) = (x+y)^2: m1 <- defmacro(x, y, expr = { x <- x + y x*x }) Executing m1 will change the input variables in the calling environment: > x <- 1 > y...

__has_cpp_attribute not a 'function-like' macro?

c++,gcc,macros,c++14

GCC 4.9 doesn't have __has_cpp_attribute, and the short-circuiting behavior of && does not extend to allowing invalid constructs to follow it. That is to say, if foo isn't defined, #if defined(foo) && foo(bar) is not valid. What you want is #if defined(__has_cpp_attribute) #if __has_cpp_attribute(deprecated) #define DEPRECATED(msg) [[deprecated(msg)]] #endif #elif OTHER_COMPILER...

Why don't I get a warning when I declare a variable with same name in a macro that already exists in a function?

c,macros,ansi

Given your code and the macro above, the C preprocessor generates the following: int main() { int temp = 999; printf("\ntemp: %d", temp); { int temp = 10; } printf("\ntemp: %d", temp); } This is the code that the C compiler receives. The inner { .. } is called a...

Execute Macro inside SQL statement

sql,macros,sas,sas-macro

In a data step, you can use call execute to do what you're describing. %Macro Max(field, table); proc sql; Select MAX(&field.) From &table.; quit; %mend; data _null_; set table_associations; call execute('%MAX('||field||','||table||')'); run; ...