Results 1 to 5 of 5

Thread: Pass symbol definitions with spaces as build options?

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Location
    Seattle, WA
    Posts
    27

    Pass symbol definitions with spaces as build options?

    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
    Code :
    -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.

    When passing the string:
    Code :
    -D ASYMBOL='two words'
    I get an OpenCL API error:
    Code :
    [CL_INVALID_BUILD_OPTIONS] : OpenCL Error : clBuildProgram failed: Invalid build options
    The error stream also prints out the build options string exactly as I have listed above.

    When passing the string:
    Code :
    -D ASYMBOL='oneword'
    I get an OpenCL compiler error:
    Code :
    <program source>:763:2: warning: multi-character character constant

    Can anyone help please?

    Implementation:
    Apple 10.7.2

  2. #2
    Junior Member
    Join Date
    Oct 2011
    Location
    Seattle, WA
    Posts
    27

    Re: Pass symbol definitions with spaces as build options?

    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.
    But I sure would like spaces!

  3. #3
    Senior Member
    Join Date
    Aug 2011
    Posts
    271

    Re: Pass symbol definitions with spaces as build options?

    Quote Originally Posted by noah_r
    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.
    But I sure would like spaces!
    For strings you need double quotes like any other C string. '' is for character constants, hence your warning message.

    I don't see why \n can't be used to escape a newline just like any other string define.

    You might need additional escapes depending on what language you're running it from. e.g. from C you will need something like

    "-Dfoo=\"foo bar\\nbaz\""

    So that after the first escape it becomes:
    -Dfoo="foo bar\nbaz"

    i.e. there is no embedded newline.

    If that doesn't work, just insert the strings manually before compiling it.

  4. #4
    Junior Member
    Join Date
    Oct 2011
    Location
    Seattle, WA
    Posts
    27

    Re: Pass symbol definitions with spaces as build options?

    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:
    Code :
    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.

  5. #5
    Senior Member
    Join Date
    Aug 2011
    Posts
    271

    Re: Pass symbol definitions with spaces as build options?

    Quote Originally Posted by noah_r
    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.
    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:
    Code :
    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.

Similar Threads

  1. Replies: 5
    Last Post: 05-29-2012, 06:30 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •