This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

About #define aa=DWORD[0x30]

If I

 #define aa=DWORD[0x30];
Can I treat aa as an integer number!

And if I
 #define aa=DBYTE[0x30];
Can I treat aa as an char number!

Thanks!

  • Thanks for your correction in the other thread.

    Beware, however, that using these macros results in DWORD[0x30] accessing an unsigned in at internal RAM address 0x60 and DBYTE[0x30] accessing an unsigned char at internal RAM address 0x30. If you are truly trying to access the 0x30'th + 1 integer or the 0x30'th + 1 char starting from the beginning of internal RAM, then you are OK using them. If you are thinking of 0x30 as an absolute internal RAM address, you will not access that location with the DWORD macro.

    I have cautioned about this previously in my 3/27/03 10:06:03 post in this thread:

    http://www.keil.com/forum/docs/thread2581.asp

  • And, hopefully to avoid a future problem, note that the syntax for the #define is incorrect. There is no equals sign in the definition, and, since this directive is part of the preprocessor and not the compiler, no semicolon is needed. The definition should look something like:

    #define aa DWORD[0x30]

    After this statement, any occurrence of the text "aa" in the source will be replaced by the text "DWORD[0x30]" before the compiler sees it. (I'd choose a longer, less likely to collide, and more descriptive name for the macro.)

    Note that DWORD is itself a macro, defined in absacc.h.

    #define DWORD ((unsigned int volatile data *) 0)

    So, after macro expansion, "aa" will turn into

    ((unsigned int volatile data *) 0)[0x30]

    In other words, the 16-bit unsigned int at address 0x60 in the data space.

    If this phrase happens to be syntactically legal C at the point where you use it, then you are in good shape. You can, for example, use this macro on the left or right side of an assignment, or as a parameter in a function.

  • Have you looked at the _at_ keyword extension?

  • In all fairness (to Keil), however, the array/index characteristics of the 'WORD versions of these macros is noted in the C51 manual. My warning came about as a result of seeing the OP's use of the same index value when using both the 'BYTE and 'WORD macros.