really funny behaviour of #define

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

IN SHORT: I have a #define that the compiler says has not been defined. It recognises the other constants defined before and after it and even recognise this #define in other files.

LONGER STORY:

I define a few constants like this:
#define MOBJ_ALARM 10
#define MOBJ_RS485_ADDR 11
#define MOBJ_RFID 12
#define M0BJ_TRANS 13
#define MOBJ_RFIDNAME 14
#define MOBJ_TEXT1 15
#define MOBJ_TEXT2 16
#define MOBJ_TEXT3 17
#define MOBJ_TEXT4 18
#define MOBJ_TEXT5 19
#define MOBJ_RS485_BAUD 20
#define MOBJ_DOOR_DELAY 21
#define MOBJ_CLOCKING 22
#define MOBJ_RECLOCK 23

These are all just ID's for different types of objects that I store in external SPI flash.

I then define their lengths like this:
#define MEM_OBJ_CUSTOM \
MOBJ_ALARM , 13 , \
MOBJ_RS485_ADDR , 1 , \
MOBJ_RFID , 3 , \
M0BJ_TRANS , 10 , \
MOBJ_RFIDNAME , (19+1) , \
MOBJ_TEXT1 , (10+1) , \
MOBJ_TEXT2 , (30+1) , \
MOBJ_TEXT3 , (30+1) , \
MOBJ_TEXT4 , (45+1) , \
MOBJ_TEXT5 , (45+1) , \
MOBJ_RS485_BAUD , 1 , \
MOBJ_DOOR_DELAY , 1 , \
MOBJ_CLOCKING , 1 , \
MOBJ_RECLOCK , 1

Again nothing strange.
I then define a table in MCU flash like this:
const unsigned char mem_ObjTable[] PROGMEM =
{
MEM_OBJ_GENERIC
MEM_OBJ_CUSTOM
};

I then use these defined obj-id's in functions like these:
memObjRd(MOBJ_TRANS, dest_p, src_addr);

And this all works good, except for the MOBJ_TRANS id. I would call it 5 times in a single file and the compiler will only give me a error relating to the last one, telling me it is "undeclared".
If I change it to MOBJ_RFID, for instance, it compiles OK and if I put in the direct value of 13 it also works OK.

I've tried to move it's position in the table up and down and even renamed it to MOBJ_F_TRANS (you can imagine what the 'F' stands for), but with no success.

Does someone have an idea of what's going on here? I use avr-gcc v3.4.1. I hope I'm missing something obvious...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I can't remember what it is but there's a command line switch to the compiler to say "only perform the pre-processor stage". Use that and -o output a pre-processed file to see how the #defines have been substituted before they are passed to the C compiler. It'll probably become clear from that as to what you have done wrong.

Cliff

Last Edited: Wed. Dec 7, 2005 - 01:53 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

PS It is the -E option that tells the compiler to *only* pre-process.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

... uh...
Maybe it's a typo in your cut-and-paste job. Or maybe it's really in your source code.

It liiks as though you're trying to invoke "MOBJ_TRANS". But the symbol being defined is "M0BJ_TRANS"

...that's a "Zero" instead of a "Oh".

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

...problem solved. Thanks Ifmorrison.

I see the font on this forum actually shows it more clearly than my editor. I use "Courier New" font. Does someone know about a font that has a 'dot' in the middle of the Zero, but is still fixed width?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You can try Fixedsys as font.

Regards

Andre