Can the precompiler process JUST the #define s?

This is a discussion on Can the precompiler process JUST the #define s? within the C Programming forums, part of the General Programming Boards category; Is there any way to get the C precompiler to interpret JUST the #defines in a piece of source code ...

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    2

    Unhappy Can the precompiler process JUST the #define s?

    Is there any way to get the C precompiler to interpret JUST the #defines in a piece of source code and output a file? I don't want the various line # references and include file jazz. The man pages lead me to believe that the precompiler won't do this, and experiments have failed. Is there any way to do this? Some other utility that will do this? Am I forced to write code to handle this?

    ( I'm writing some code that will be going into Oracles proC precompiler, but it does NOT interpret my #defines prior to doing its thing. )

    e.g.

    I have a

    #define BORK bork,bork,bork

    main()
    {
    char bork = 'C';
    printf("bork %c;%c;%c",BORK):
    return(1);
    }


    I want the output to just be

    main()
    {
    char bork = 'C';
    printf("bork %c;%c;%c",bork,bork,bork):
    return(1);
    }


    Thanks in advance

    MT

  2. #2
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    I almost understand what you mean, Can you explain it a bit
    more chronologic?

  3. #3
    Registered User
    Join Date
    Feb 2003
    Posts
    2
    Sorry, lots of frustrations leaking in to that.

    Say you run the preprocessor against the below source.

    #include <stdio.h>

    #define BORK 10

    main()
    {
    int a=BORK;
    printf("a %d",a);
    return(1);
    }

    cc -E f.c>file.c
    in 'file.c' you'll get something like
    # 1 "f.c"

    # 1 "/usr/include/stdio.h"
    # 6

    # 1 "/usr/include/sys/stdsyms.h"
    # 336

    blah blah blah

    main()
    {
    int a=10 ;
    printf("a %d",a);
    return(1);
    }

    What I want to happen is for just the #define to be processed and substituted throughout the code without all the line control info and include stuff.

  4. #4
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    Oke, I think i understand now. And no, I've never seen that
    anywhere. And i can hardly imagine why you need this?

  5. #5
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  6. #6
    booyakasha
    Join Date
    Nov 2002
    Posts
    208
    with gcc you can use the -E flag

    gcc -E sourcefile.cc

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C problem with legacy code
    By andy_baptiste in forum C Programming
    Replies: 4
    Last Post: 05-19-2008, 06:14 AM
  2. Accessing syscalls from C
    By lilcoder in forum C Programming
    Replies: 17
    Last Post: 09-19-2007, 02:27 PM
  3. C Programming 2d Array Question
    By jeev2005 in forum C Programming
    Replies: 3
    Last Post: 04-26-2006, 03:18 PM
  4. NAQ: Everything you never wanted to know about CPP
    By evildave in forum C Programming
    Replies: 21
    Last Post: 12-12-2005, 09:56 AM
  5. DOS, Serial, and Touch Screen
    By jon_nc17 in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 01-08-2003, 03:59 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21