Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > #define problem

Reply
Thread Tools

#define problem

 
 
Rayn
Guest
Posts: n/a
 
      04-26-2007
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.

 
Reply With Quote
 
 
 
 
Sumit Rajan
Guest
Posts: n/a
 
      04-26-2007
Rayn wrote:
> 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.
--
Sumit Rajan <(E-Mail Removed)>
 
Reply With Quote
 
 
 
 
Sumit Rajan
Guest
Posts: n/a
 
      04-26-2007
Sumit Rajan wrote:
> Rayn wrote:
>> Hi All,
>>
>> I am defining as follows,
>>
>> #define REIN (a) if(a == NULL) return -1;


You may like to avoid macros as far as possible. See:
http://www.parashift.com/c++-faq-lit...s.html#faq-9.5


--
Sumit Rajan <(E-Mail Removed)>
 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      04-26-2007
Rayn wrote:
> Hi All,
>
> I am defining as follows,
>
> #define REIN (a) if(a == NULL) return -1;
>

Don't. Use an inline function.

--
Ian Collins.
 
Reply With Quote
 
Martijn van Buul
Guest
Posts: n/a
 
      04-26-2007
* Ian Collins:
> Rayn wrote:
>> Hi All,
>>
>> I am defining as follows,
>>
>> #define REIN (a) if(a == NULL) return -1;
>>

> 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.

--
Martijn van Buul - http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
Ron Natalie
Guest
Posts: n/a
 
      04-26-2007
Ian Collins wrote:
> Rayn wrote:
>> Hi All,
>>
>> I am defining as follows,
>>
>> #define REIN (a) if(a == NULL) return -1;
>>

> Don't. Use an inline function.
>


And just how is an inline function going to do the control construct
he has above?
 
Reply With Quote
 
siddhu
Guest
Posts: n/a
 
      04-26-2007
On Apr 26, 5:04 am, Ian Collins <(E-Mail Removed)> wrote:
> Rayn wrote:
> > Hi All,

>
> > I am defining as follows,

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




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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem problem problem :( Need Help Mike ASP General 2 05-11-2004 08:36 AM



Advertisments