printing macro's at compile time

This is a discussion on printing macro's at compile time within the Linux Programming forums, part of the Platform Specific Boards category; Is it possible to print macro's with gcc during compile time? something like Code: #define MACRO 4 #pragma warning MACRO ...

  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    330

    printing macro's at compile time

    Is it possible to print macro's with gcc during compile time?

    something like

    Code:
    #define MACRO 4
    
    #pragma warning MACRO
    And that gcc says 4 then during compilation

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,824
    What does the manual page tell you?
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Jan 2007
    Posts
    330
    a lot, but not what im looking for

  4. #4
    Registered User
    Join Date
    Jan 2007
    Posts
    330
    nobody knows?

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Since you're looking for compiler-specific behaviour anyway, just try it out.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  6. #6
    Registered User
    Join Date
    Jan 2007
    Posts
    330
    jah, of course I tried it but it doesnt work. The original problem why I wanted to do this is solved but I'd still like to know how this is possible, could be handy next time.
    gcc docs say lots of things about pragma's, but nothing about printing macro's

  7. #7
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    What does it print?
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  8. #8
    C / C++
    Join Date
    Jan 2006
    Location
    The Netherlands
    Posts
    312
    You can add macro's during compiling using this:

    Code:
    gcc source.c -DMACRO=4
    This is the same as:
    Code:
    #define MACRO 4
    It's not the solution to your question, but you can "view" your macro's during the compiling.
    Operating Systems:
    - Ubuntu 9.04
    - XP

    Compiler: gcc

  9. #9
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    You can use a sort of if-else construct.
    Code:
    #define DEBUG 1
    
    #if DEBUG == 1
        #pragma warning Debug mode on.
    #elif DEBUG == 0
        #pragma warning Release mode on.
    #else
        #pragma warning Invalid DEBUG macro.
    #endif
    But I'm sure you've already thought of that.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  10. #10
    Registered User
    Join Date
    Jan 2007
    Posts
    330
    all I get is

    c:\bla.c(245): warning: ignoring #pragma warning xxx

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Clarification on compile time error
    By John_L in forum C Programming
    Replies: 2
    Last Post: 12-04-2007, 11:59 AM
  2. Military Time Functions
    By BB18 in forum C Programming
    Replies: 6
    Last Post: 10-10-2004, 02:57 PM
  3. Replies: 0
    Last Post: 11-29-2002, 10:24 PM
  4. compile time errors!!!!
    By devour89 in forum C++ Programming
    Replies: 6
    Last Post: 11-18-2002, 05:02 PM
  5. Debugging mode selection during compile time
    By YALINI in forum C Programming
    Replies: 1
    Last Post: 09-03-2001, 10:56 AM

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