Thread: Is there any way to access string indexes in preprocessor?

  1. #1
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    657

    Is there any way to access string indexes in preprocessor?

    I tried something like this:
    Code:
    #define _TOSTR(SRC) (#SRC)
    #define TOSTR(SRC) _TOSTR(SRC)
    #if (TOSTR(__INT64_TYPE__)[0]) == '\0'
    #message "__INT64_TYPE__ = int"
    #else
    #message "__INT64_TYPE__ = ?"
    #endif
    But that just sprung up the following error:
    Code:
    ge.c:211:26: error: token ""long int"" is not valid in preprocessor expressions
    Is there a way to do this? This is mainly curiosity since I can work around the lack of it if need be.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,537
    I'm pretty sure you can't do that.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    657
    Oh well, was worth a shot anyway, woulda been nice to chek which prefix to use via the type name, I suppose I could programmatically add it, just takes from the concatenation ability, but eh I should be fine with just the #if stuff

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Get matrix indexes from the value
    By koplersky in forum C++ Programming
    Replies: 6
    Last Post: 10-17-2013, 02:45 PM
  2. String indexes.
    By Crux in forum C++ Programming
    Replies: 1
    Last Post: 02-03-2011, 01:37 PM
  3. Getting Indexes
    By satty in forum C Programming
    Replies: 2
    Last Post: 08-09-2010, 01:11 AM
  4. Replies: 2
    Last Post: 03-08-2009, 08:54 PM
  5. Preprocessor string pasting fun
    By ggambett in forum C Programming
    Replies: 6
    Last Post: 11-11-2004, 06:40 PM

Tags for this Thread