#defines of numeric constants

Post your requests and ideas on the future development of mikroC.
Post Reply
Author
Message
CGEngineering
Posts: 144
Joined: 09 May 2007 23:31
Location: Florence - Italy
Contact:

#defines of numeric constants

#1 Post by CGEngineering » 25 Sep 2008 11:42

Hi there,

in my opinion, #defines of numeric constants would lead to a ROM constant, not a RAM variable!.

Example:

Code: Select all

#define NUMBER_OF_REPLIES        5
would be equal to:

Code: Select all

const unsigned short NUMBER_OF_REPLIES = 5;
or, for a string:

Code: Select all

#define myString        "MyStringWithMikroC"
would be equal to:

Code: Select all

const char myString[] = "MyStringWithMikroC";
in order to save RAM, assumed that PICmicros have really a few RAM quantitative

Enjoy!
CG

idakota
Posts: 334
Joined: 27 Sep 2006 08:07
Location: Pretoria/South Africa
Contact:

#2 Post by idakota » 25 Sep 2008 17:40

I might be wrong, but I believe that #defines are compiler directives and the compiler essentially replaces all instances of the defined constant in the source files before compiling, therefore a numeric constant is in fact stored in ROM.

CGEngineering
Posts: 144
Joined: 09 May 2007 23:31
Location: Florence - Italy
Contact:

#3 Post by CGEngineering » 25 Sep 2008 19:16

idakota wrote:I might be wrong, but I believe that #defines are compiler directives and the compiler essentially replaces all instances of the defined constant in the source files before compiling, therefore a numeric constant is in fact stored in ROM.
Uhm, i noted that numeric constants are stored in rom, but strings don't... so you're right if you say that my post isn't almost correct

I noted, howewer, that is convenient to make a #define or a const everytime a number is written more than once, to avoid immediate addressing with a RAM variable that will never be modified (so can be stored in ROM)

Bye
CG

Post Reply

Return to “mikroC Wish List”