I would like to define some macros for my OpenCL program, where the macro definition will have several spaces. (also potentially special characters like newline and tab)
I want to pass the definition as
-D=my_string
to clBuildProgram() as the options argument.
I have tried enclosing my_string in single quotes and double quotes. Either way, the quote characters seem to not do what I want when the definition contains a space, or are added to the symbol definition if there are no spaces in the definition.
never mind the about newlines and tabs. I can see they aren’t going to be allowed. From the reference pages:
The contents of definition are tokenized and processed as if they appeared during translation phase three in a `#define’ directive. In particular, the definition will be truncated by embedded newline characters.
Thanks for the thought, but I do not want to produce a string literal, I want a code literal. I’m working on doing some light dynamic OpenCL code generation.
Suppose I wanted to replace a macro symbol INSERT_DECLARATION_HERE within a source file with the characters:
float sum(float a, float b);
There is no way to specify that without whitespace. And you can see in context, I don’t want a string literal in double quotes; I want code.
Yes, I acknowledge that I could do my own source code search and replace before sending the source code to clBuildProgram(). However, what I am trying to accomplish is straightforward enough that I just want the OpenCL preprocessing stage to take care of this for me.
You do realise C compilers totally ignore newlines out side of strings, so why would you even want to add them?
Suppose I wanted to replace a macro symbol INSERT_DECLARATION_HERE within a source file with the characters:
float sum(float a, float b);
There is no way to specify that without whitespace. And you can see in context, I don’t want a string literal in double quotes; I want code.
Yes, I acknowledge that I could do my own source code search and replace before sending the source code to clBuildProgram(). However, what I am trying to accomplish is straightforward enough that I just want the OpenCL preprocessing stage to take care of this for me.
Well I was only trying with gcc, it seems the opencl compiler is broken wrt -D.
Since you’re obviously choosing a few pre-set values just pass in an option which uses the in-line pre-processor to select what to generate. Otherwise write your own generator or template processor - the latter wouldn’t be difficult.