C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 07-07-2009, 12:54 AM   #1
Registered User
 
Join Date: Apr 2009
Posts: 53
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
sanddune008 is offline   Reply With Quote
Old 07-07-2009, 01:16 AM   #2
C++ Witch
 
laserlight's Avatar
 
Join Date: Oct 2003
Location: Singapore
Posts: 10,352
Try changing this:
Code:
#define FREE ( a )                        bBosMemFree ( a )
to:
Code:
#define FREE(a) bBosMemFree( a )
__________________
C + C++ Compiler: MinGW port of GCC
Build + Version Control System: SCons + Bazaar

Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
laserlight is offline   Reply With Quote
Old 07-07-2009, 01:34 AM   #3
Registered User
 
Join Date: Apr 2009
Posts: 53
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)
sanddune008 is offline   Reply With Quote
Old 07-07-2009, 01:46 AM   #4
C++ Witch
 
laserlight's Avatar
 
Join Date: Oct 2003
Location: Singapore
Posts: 10,352
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.
__________________
C + C++ Compiler: MinGW port of GCC
Build + Version Control System: SCons + Bazaar

Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
laserlight is offline   Reply With Quote
Old 07-07-2009, 02:00 AM   #5
Registered User
 
Join Date: Apr 2009
Posts: 53
Thanks for your time.....

You were right there shouldn't space b/w FREE(a)
sanddune008 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 07:20 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22