Thread: How can I change #define values without recompiling?

  1. #1
    Registered User
    Join Date
    Jul 2014
    Posts
    2

    How can I change #define values without recompiling?

    I need the user to be able to run my program with different values *without* recompiling it. I was a C programmer years (and years) ago and vaguely recall being able to do this. I thought I used #defines in my .h file but the changes don't seem to work in my current environment (code::blocks) unless I recompile.

    Any ideas?

    Thanks.

  2. #2
    Registered User
    Join Date
    Sep 2007
    Posts
    1,012
    You can't. Macros (which are created by #define) are a compile-time construct.

    What are you trying to achieve? If you want the user to be able to select things at runtime, you could use command-line arguments, environment variables, or configuration files, etc etc etc. But it all depends on what your actual goal is.

  3. #3
    Registered User
    Join Date
    Jul 2014
    Location
    Amarillo, Texas
    Posts
    104
    You could make the value you want to change something that you read in from the keyboard but other than that I can't think of any way that you can change values in a program without recompiling it.

    Will

  4. #4
    Registered User
    Join Date
    Jul 2014
    Posts
    2
    I currently use some command-line args and also have the user answer a series of questions but I don't like it.
    Maybe a config file is what I am thinking of....

    Thanks.

  5. #5
    Registered User
    Join Date
    May 2009
    Posts
    3,748
    Quote Originally Posted by maryfsan View Post
    I currently use some command-line args and also have the user answer a series of questions but I don't like it.
    Maybe a config file is what I am thinking of....

    Thanks.
    INI file - Wikipedia, the free encyclopedia


    You might be thinking of INI files; a type of config file of common use about 15 years ago.
    It was used a lot in Windows 95/98 and earlier. It is still used, today, but Windows Registry has almost replaced it, completely.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  6. #6
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Quote Originally Posted by stahta01 View Post
    INI file - Wikipedia, the free encyclopedia


    You might be thinking of INI files; a type of config file of common use about 15 years ago.
    It was used a lot in Windows 95/98 and earlier. It is still used, today, but Windows Registry has almost replaced it, completely.

    Tim S.
    Well actually nowdays we've almost come full circle it seems. Think ClickOnce etc.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. enum values not working in #define?
    By MattJ812 in forum C++ Programming
    Replies: 22
    Last Post: 01-15-2011, 06:36 AM
  2. using define to change the syntax keywords,,
    By Anddos in forum C++ Programming
    Replies: 3
    Last Post: 12-02-2005, 06:07 PM
  3. Recompiling C after Oracle 9i upgrade?
    By marcusg in forum C Programming
    Replies: 2
    Last Post: 06-02-2005, 05:55 AM
  4. Multiple values for a #define
    By heygirls_uk in forum C Programming
    Replies: 4
    Last Post: 01-22-2004, 05:48 AM
  5. #define CONSTANT - how to change it's value?
    By gogo in forum C Programming
    Replies: 4
    Last Post: 03-10-2003, 11:34 AM

Tags for this Thread