473,396 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

where is different???

1.
#define MA \
....
{
i = j;
}
....
2
#define MA \
....
do{
i = j;
}while(0);

thanks for your answer...
Nov 13 '05 #1
3 1651
wende <sj**********@yahoo.co.uk> wrote:
1.
#define MA \
...
{
i = j;
}
...
2
#define MA \
...
do{
i = j;
}while(0);


The usual idiom is to leave off the trailing semicolon - and it's only
useful with multiple-statement macros, so it is this:

#define MA \
{ \
i = j; \
j = k; \
}

versus this:

#define MA \
do { \
i = j; \
j = k; \
} while (0)

With the former definition, this code:

if (test)
MA;
else
puts("no");

is an error, but with the latter definition it is not. This is because
MA; is two statements with the former definition and one statement with
the latter.

- Kevin.

Nov 13 '05 #2
Kevin Easton <kevin@-nospam-pcug.org.au> wrote:
wende <sj**********@yahoo.co.uk> wrote:
<snip original>
The usual idiom is to leave off the trailing semicolon - and it's only
useful with multiple-statement macros, so it is this: #define MA \
{ \
i = j; \
j = k; \
} versus this: #define MA \
do { \
i = j; \
j = k; \
} while (0) With the former definition, this code: if (test)
MA;
else
puts("no"); is an error, but with the latter definition it is not. This is because
MA; is two statements with the former definition and one statement with
the latter.

With the first definition, this will work:

if(test)
MA
else
puts("no");

However, the requirement of the trailing semicolon in the
second definition is much more idiomatic.

Alex
Nov 13 '05 #3
Peter "Shaggy" Haywood <ph******@alphalink.com.au.stop.spam> wrote:
Groovy hepcat Kevin Easton was jivin' on Thu, 14 Aug 2003 23:40:06 GMT
in comp.lang.c.
Re: where is different???'s a cool scene! Dig it!
#define MA \
{ \
i = j; \
j = k; \
}

versus this:

#define MA \
do { \
i = j; \
j = k; \
} while (0)

With the former definition, this code:

if (test)
MA;
else
puts("no");

is an error, but with the latter definition it is not. This is because
MA; is two statements with the former definition and one statement with
the latter.


Piffle! They're both perfectly legal. You've never heard of a null
statement? Look that up in your C manual.


How about *you* look up the syntax of the if statement in *your* C
manual?

The expansion of the given if statement using the former definition of
MA is:

if (test)
{
i = j;
j = k;
};
else
puts("no");

Which isn't legal. There can only be *one* statement between the test
and else part of an if statement.

- Kevin.

Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

47
by: Andrey Tatarinov | last post by:
Hi. It would be great to be able to reverse usage/definition parts in haskell-way with "where" keyword. Since Python 3 would miss lambda, that would be extremly useful for creating readable...
36
by: Jack Hughes | last post by:
This argument has come up two or three times lately. We have a web standards document at our company that say "Use valid HTML 4; We don't recommend switching to DIV-based CSS-P for layout just...
2
by: BoB Teijema | last post by:
Hi all, One of our companies is having problems with a query on a linked server. They have two servers, serverA and serverB. On serverA they have set up a linked server to serverB. Query:...
2
by: G.J. v.d. Kamp | last post by:
Hi all, I have one for all the blackbelters out there: is there a way i can make a stored procedure where i can control the where statement with variables? I have to do some complex...
7
by: MLH | last post by:
Where is system.mdw normally stored in typical A97 installation?
23
by: rohit | last post by:
Hi, In my couple of years of experience, I have never found a single instance where I needed to use unions and bitfields(though I have used structures).I was just imagining where would these find...
1
by: virendra.chandra | last post by:
hi guys, this is virendra. I am in big trouble to handle date situation using where clause. i am using ormapper. if the sqlserver and application server has different date format(different...
20
by: Frank-O | last post by:
Hi , Recently I have been commited to the task of "translating" some complex statistical algorithms from Matlab to C++. The goal is to be three times as fast as matlab ( the latest) . I've...
34
by: linq936 | last post by:
Hi, I just did the following test: 1:void main(void){ 2: int p = 1; 3: int* pp = &p; 4: int c = p * pp; 5: int d = p + pp; 6:}
41
by: Miroslaw Makowiecki | last post by:
Where can I download Comeau compiler as a trial version? Thanks in advice.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.