|
-
May 10th, 1999, 12:45 PM
#1
Is it bad coding practice to use #defines for string literals ?
During a recent code review it was pointed out to me that it is bad to use #define for string literals because :
while making your debug build your compiler makes a separate copy of the string for each use, in your exe, while in your release build it ptimizes this to make just one string
Now if you are passing your string to a function as an argument and that function modifies it, you
are safe in your debug build becoz each usage is a new string however, in your release build you
are dead cause the subsequent uses of that string points to modified/corrupt data
I have therefore been advised to use a global array of const char*s.
Any opinions/alternative solutions will be welcome
Thanx
sanjay
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|