Problem with #defined values
-
In a header file I have #define NOMINDEX 0 ... #define ETABLESIZE 5 In the source file that includes this header, the following doesn't seem to work (it's writing 0 to the buffer (and in the watch window in VS, it's saying it doesn't recognise the symbols defined) sprintf_s( eBuff, 16, "%d", energyTable[ETABLESIZE*sel + NOMINDEX] ); if I add this line before it, "e" is correctly assigned to 5 int e = ETABLESIZE; sprintf_s( eBuff, 16, "%d", energyTable[ETABLESIZE*sel + NOMINDEX] ); In other parts of my cpp file I use these constants and they seem to work correctly. Have I done something incredibly stupid? cheers Lee
-
In a header file I have #define NOMINDEX 0 ... #define ETABLESIZE 5 In the source file that includes this header, the following doesn't seem to work (it's writing 0 to the buffer (and in the watch window in VS, it's saying it doesn't recognise the symbols defined) sprintf_s( eBuff, 16, "%d", energyTable[ETABLESIZE*sel + NOMINDEX] ); if I add this line before it, "e" is correctly assigned to 5 int e = ETABLESIZE; sprintf_s( eBuff, 16, "%d", energyTable[ETABLESIZE*sel + NOMINDEX] ); In other parts of my cpp file I use these constants and they seem to work correctly. Have I done something incredibly stupid? cheers Lee
The answer of course is, yes, I was doing something incredibly stupid. I really ought to try the count to 10 rule before posting :-) unsurprisingly, sprintf_s( eBuff, 16, "%.0f", energyTable[ETABLESIZE*sel + NOMINDEX] ); works rather better, since energyTable is a float array DOH! sorry.....
-
In a header file I have #define NOMINDEX 0 ... #define ETABLESIZE 5 In the source file that includes this header, the following doesn't seem to work (it's writing 0 to the buffer (and in the watch window in VS, it's saying it doesn't recognise the symbols defined) sprintf_s( eBuff, 16, "%d", energyTable[ETABLESIZE*sel + NOMINDEX] ); if I add this line before it, "e" is correctly assigned to 5 int e = ETABLESIZE; sprintf_s( eBuff, 16, "%d", energyTable[ETABLESIZE*sel + NOMINDEX] ); In other parts of my cpp file I use these constants and they seem to work correctly. Have I done something incredibly stupid? cheers Lee
Could it be that your sel variable is 0 and you just didn't notice?
> The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <
-
In a header file I have #define NOMINDEX 0 ... #define ETABLESIZE 5 In the source file that includes this header, the following doesn't seem to work (it's writing 0 to the buffer (and in the watch window in VS, it's saying it doesn't recognise the symbols defined) sprintf_s( eBuff, 16, "%d", energyTable[ETABLESIZE*sel + NOMINDEX] ); if I add this line before it, "e" is correctly assigned to 5 int e = ETABLESIZE; sprintf_s( eBuff, 16, "%d", energyTable[ETABLESIZE*sel + NOMINDEX] ); In other parts of my cpp file I use these constants and they seem to work correctly. Have I done something incredibly stupid? cheers Lee
It should work, indeed. That stated, why don't you use an enum for your symbols? :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]