Re: GCC compile time string comparison

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 18 August 2011 11:52, Pintu Agarwal wrote:
> Hi,
>
> I wanted to do compile time string const comparison in a macro call
> but I could not find anything in GCC.
>
> I tried using __builtin_ extended option but it is not working inside a macro.
> Here is the sample code:
>
> #define STRCMP(s1,s2)       __builtin_strcmp(s1,s2)
>
> int main()
> {
>        #if STRCMP("pintu1","pintu2")
>                printf("Equal...\n");
>        #else
>                printf("Not Equal...\n");
>        #endif
>
>        return 0;
> }
>
> But I am getting this error : error: missing binary operator before token "("
>
> I tried other option such as __builtin_expect, __builtin_constant_p
> etc but same problem when used inside macro call

The preprocessor can only expand macros and perform simple arithmetic
on constant expressions, it can't call functions. That includes
builtin functions.

Compile-time string comparison is just about possible by abusing C++
templates, but you probably don't want to go there.



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux