#define problem

R

Rayn

Hi All,

I am defining as follows,

#define REIN (a) if(a == NULL) return -1;

when I try to use this thing in my function like ..

void abc(char* aName)
{
REIN(aName);
}

It gives me a compiler error .. Undefined Identifier "a" ..

what can be the problem?

thannks in Advance.

...
KiraN Puranik.
 
S

Sumit Rajan

Rayn said:
Hi All,

I am defining as follows,

#define REIN (a) if(a == NULL) return -1;

You probably want to change that to:
#define REIN(a) if(a == NULL) return -1

(Notice the space that I have removed just after "REIN" and before "(a)")
when I try to use this thing in my function like ..

void abc(char* aName)
{
REIN(aName);
}

Now (assuming you have made the change stated above) you have a
completely different issue. You have stated above that abc() is *void*
function. However, when you expand the macro REIN, you get:

void abc(char* aName)
{
if(aName == 0) return -1;
}

You're attempting to return a value from a void function.

Regards,
Sumit.
 
M

Martijn van Buul

* Ian Collins:
Don't. Use an inline function.

Not that I'm disagreeing with the general sentiment, but using an inline
function wouldn't work here, would it? Or how did you plan to use an inline
function that's capable of aborting the calling function?

OP might want to use

#define REIN(a) do { if (!(a)) return -1; } while(false)

although I wouldn't use it either, as there's little benefit over just
using the if-statement directly.
 
S

siddhu

You can use Inline functions.

But for this case you need to remove space between REIN and (a) in the
macro.
And do not return -1 if your function has void as return value.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,796
Messages
2,569,645
Members
45,367
Latest member
Monarch

Latest Threads

Top