Compiling for variable macros

This is a discussion on Compiling for variable macros within the C Programming forums, part of the General Programming Boards category; Hey, I am running a programming course and want to distribute executable binaries of the model solution of the programming ...

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    1

    Compiling for variable macros

    Hey,

    I am running a programming course and want to distribute executable binaries of the model solution of the programming assignment, not the source. The problem model solution requires macros to be altered, which affect the behaviour of the program, which affects what the source code looks like for the compiler.

    Instead of distributing multiple binaries or rewriting the code; is there a way to compile for all possible post pre-processor source code and allow the user to alter the macros in a separate header file? In this way I could distribute a single object file and a separate header file which could be linked by the user without them seeing the original source.

    Eg.

    my_code.c (which will be distributed as .o object file)
    Code:
    //code
    #ifdef DEBUG
    print debug info
    #endif
    
    //more code
    
    #ifdef CLEAN_UP
    clean up
    #else
    dont clean up
    #endif
    my_header.h (a possible user header)
    Code:
    //#define DEBUG
    #define CLEAN_UP
    my_header.h (another possible user header)
    Code:
    #define DEBUG
    #define CLEAN_UP
    Last edited by drew.woods; 04-27-2009 at 02:55 PM.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You don't have them alter macros after it's been compiled. That wouldn't make any sense.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    I smell a good place to use command line arguments and conditionals in your code. Either that or polymorphism via function pointers but I am not a C expert.

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    It really depends on how much, or rather what type of stuff they're needing to include. Simple stuff, like deciding if you are going to show debug info or not can be done as Wraithan said, with command line args. But if for example, you need to include different headers so it can run on different platforms, then that's not something you can do without recompiling.


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Order of execution of preprocessor macros
    By DL1 in forum C Programming
    Replies: 2
    Last Post: 04-02-2009, 06:52 PM
  2. function definition with macros
    By toshog in forum C++ Programming
    Replies: 2
    Last Post: 03-08-2009, 09:22 PM
  3. Macros inside of macros
    By Chewie8 in forum C Programming
    Replies: 2
    Last Post: 02-24-2008, 02:51 AM
  4. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  5. Visual C++ and UNICODE - _t macros
    By nvoigt in forum Windows Programming
    Replies: 2
    Last Post: 04-22-2005, 07:42 AM

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