Thread: Problem with macros..

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    145

    Problem with macros..

    I have following code
    Using microcontrollers

    Code:
    #define MALLOC(size)                  pvBosMemAlloc( size )
    #define FREE ( a )                        bBosMemFree ( a )
    
    typedef struct {
                              uint8 i;
                              char ch[6];
    }mine;
    
    uint8 zcl_SendCommand(mine *pMsg)
    {
       mine *rcv;
       rcv = MALLOC(sizeof(mine));
    
       //Some code
     
      FREE (rcv);
    
    }
    I get following errors:

    Source\zcl.c:267: error: 'a' undeclared (first use in this function)
    Source\zcl.c:267: error: (Each undeclared identifier is reported only once
    Source\zcl.c:267: error: for each function it appears in.)
    Source\zcl.c:267: error: expected ';' before 'bBosMemFree'


    What may be wrong with the code.....

    Thanks

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Try changing this:
    Code:
    #define FREE ( a )                        bBosMemFree ( a )
    to:
    Code:
    #define FREE(a) bBosMemFree( a )
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Apr 2009
    Posts
    145
    Thanks for your time......

    Quote Originally Posted by laserlight View Post
    Try changing this:
    Code:
    #define FREE ( a )                        bBosMemFree ( a )
    to:
    Code:
    #define FREE(a) bBosMemFree( a )
    How does that help?

    Anyways i tried didn't compile had same error....

    Why does the error states:

    error: 'a' undeclared (first use in this function)

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by sanddune008
    How does that help?
    It should: the space means that you are defining FREE to be "(a) bBosMemFree( a )" instead of defining FREE(a) to be "bBosMemFree( a )".

    Quote Originally Posted by sanddune008
    Anyways i tried didn't compile had same error....

    Why does the error states:

    error: 'a' undeclared (first use in this function)
    My guess is that you tried wrongly. Try this test program:
    Code:
    #include <stddef.h>
    
    void *pvBosMemAlloc(size_t size)
    {
        return NULL;
    }
    
    void *bBosMemFree(void *p)
    {
        return p;
    }
    
    #define MALLOC(size) pvBosMemAlloc( size )
    #define FREE(a)      bBosMemFree( a )
    
    typedef unsigned char uint8;
    
    typedef struct {
        uint8 i;
        char ch[6];
    } mine;
    
    uint8 zcl_SendCommand(mine *pMsg)
    {
        mine *rcv;
        rcv = MALLOC(sizeof(mine));
    
        /*Some code*/
    
        FREE(rcv);
    
        return 0;
    }
    
    int main(void)
    {
        return 0;
    }
    To demonstrate your error, change this:
    Code:
    #define FREE(a)      bBosMemFree( a )
    to:
    Code:
    #define FREE (a)      bBosMemFree( a )
    If you still face the same error after copying and pasting, then you should report a compiler bug to your compiler vendor.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Apr 2009
    Posts
    145
    Thanks for your time.....

    You were right there shouldn't space b/w FREE(a)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM