The Daily Static
  The Daily Static
UF Archives
Register
UF Membership
Ad Free Site
Postcards
Community

Geekfinder
UFie Gear
Advertise on UF

Forum Rules
& FAQ


Username

Password


Create a New Account

 
 

Back to UserFriendly Strip Comments Index

Random C pre-processor question. by LionsPhil2004-12-19 13:25:44
  Why not find out? by Arachnid 2004-12-19 13:37:30
arachnid@deimos arachnid$ cat > test.c
#define INFIN_REPEATS 123
#define CARDS (INFIN_REPEATS * 256)
int main() {
        printf("%d\n", CARDS);
}

arachnid@deimos arachnid$ gcc -E test.c
# 1 "test.c"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "test.c"


int main() {
 printf("%d\n", (123 * 256));
}
Answer: No, but I'm betting the compiler will:
arachnid@deimos arachnid$ gcc -S test.c -o -
        .file   "test.c"
        .section        .rodata
.LC0:
        .string "%d\n"
        .text
        .p2align 2,,3
.globl main
        .type   main, @function
main:
        <...>
        pushl   $31488
        <...>
        .ident  "GCC: (GNU) 3.4.2 [FreeBSD] 20040728"
And there you have it. The preprocessor won't, but even without optimisation settings, GCC will.
[ Reply ]
    Thankee. (n/t) by LionsPhil2004-12-19 13:53:23

 

[Todays Cartoon Discussion] [News Index]

Come get yer ARS (Account Registration System) Source Code here!
All images, characters, content and text are copyrighted and trademarks of J.D. Frazer except where other ownership applies. Don't do bad things, we have lawyers.
UserFriendly.Org and its operators are not liable for comments or content posted by its visitors, and will cheerfully assist the lawful authorities in hunting down script-kiddies, spammers and other net scum. And if you're really bad, we'll call your mom. (We're not kidding, we've done it before.)