473,378 Members | 1,457 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,378 software developers and data experts.

Macro function with void argument list


Is there any way of achieving this? Something like:

#define END_SCAN() (EndScan(),CleanUpAfterScan())

(Yes I realise this doesn't work)

I want to be able to invoke it as:

END_SCAN();

rather than:

END_SCAN;

Martin

Oct 25 '07 #1
7 3364
Martin Wells wrote:
Is there any way of achieving this? Something like:

#define END_SCAN() (EndScan(),CleanUpAfterScan())

(Yes I realise this doesn't work)
The idiom that I normally use is:

#define END_SCAN() do{EndScan();CleanUpAfterScan();}while(0)
Oct 25 '07 #2
Martin Wells wrote:
Is there any way of achieving this? Something like:

#define END_SCAN() (EndScan(),CleanUpAfterScan())

(Yes I realise this doesn't work)
In what way does it fail to work?
I want to be able to invoke it as:

END_SCAN();

rather than:

END_SCAN;
I don't see what's stopping you. Maybe more context
would clarify the problem.

--
Eric Sosman
es*****@ieee-dot-org.invalid
Oct 25 '07 #3
Keith Willis wrote:
Martin Wells wrote:
>Is there any way of achieving this? Something like:

#define END_SCAN() (EndScan(),CleanUpAfterScan())

(Yes I realise this doesn't work)

The idiom that I normally use is:

#define END_SCAN() do{EndScan();CleanUpAfterScan();}while(0)
Why bother with the unnecessary do/while? Just use a bare block.
Oct 25 '07 #4
[comp.lang.c] Philip Potter <pg*@see.sig.invalidwrote:
Keith Willis wrote:
>#define END_SCAN() do{EndScan();CleanUpAfterScan();}while(0)
Why bother with the unnecessary do/while? Just use a bare block.
The FAQ explains why a bare block is not good enough:
http://c-faq.com/cpp/multistmt.html

--
C. Benson Manica | I appreciate all corrections, polite or otherwise.
cbmanica(at)gmail.com |
----------------------| I do not currently read any posts posted through
sdf.lonestar.org | Google groups, due to rampant unchecked spam.
Oct 25 '07 #5
Martin Wells wrote:
>
Is there any way of achieving this? Something like:

#define END_SCAN() (EndScan(),CleanUpAfterScan())

(Yes I realise this doesn't work)
Define "doesn't work".
I want to be able to invoke it as:

END_SCAN();

rather than:

END_SCAN;
What happens when you define END_SCAN() as above, and invoke is as
END_SCAN(); as desired?

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h|
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>
Oct 25 '07 #6
Eric:
I don't see what's stopping you. Maybe more context
would clarify the problem.

Oh I didn't realise that that's actually possible. My compiler puked
the first time I tried it... I'll try it again tomorrow.

Martin

Oct 25 '07 #7
Christopher Benson-Manica <at***@faeroes.freeshell.orgwrites:
[comp.lang.c] Philip Potter <pg*@see.sig.invalidwrote:
>Keith Willis wrote:
>>#define END_SCAN() do{EndScan();CleanUpAfterScan();}while(0)
>Why bother with the unnecessary do/while? Just use a bare block.

The FAQ explains why a bare block is not good enough:
http://c-faq.com/cpp/multistmt.html
But in this particular case, a block isn't necessary at all, since the
expansion contains only function calls (which are expressions, only
becoming statements when you add a semicolon).

#define END_SCAN() ( End_Scan(), CleanUpAfterScan() )

You only need a block when the expansion contains control flow. Even
then, an if/else statement can often be replaced with a ?: operator.

I recommend this only for macro definitions. In ordinary code,
replacing ";" with "," and if/else with "?:" will often (but not
always) merely obfuscate the code with no increase in performance.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Oct 25 '07 #8

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

Similar topics

25
by: Andrew Dalke | last post by:
Here's a proposed Q&A for the FAQ based on a couple recent threads. Appropriate comments appreciated X.Y: Why doesn't Python have macros like in Lisp or Scheme? Before answering that, a...
699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
3
by: John | last post by:
Please, consider this macro: #define mymacro(arg1, arg2) arg1 and arg2 Then it is used: mymacro(boys, girls) How is its expansion?
7
by: A. Saksena | last post by:
Hi all, Is it possible to write a function or a macro in C++, which is capable of accepting any number of arguments. To give an example, the following should be possible: - ...
44
by: Simon Morgan | last post by:
Hi, Can somebody please help me grok the offsetof() macro? I've found an explanation on http://www.embedded.com/shared/printableArticle.jhtml?articleID=18312031 but I'm afraid it still...
10
by: Praveen.Kumar.SP | last post by:
Hi Could anyone solve the problem for the code below The Code: #include "stdio.h" #include "iostream.h" void Temp( int a, char* str,...)
12
by: Laurent Deniau | last post by:
I was playing a bit with the preprocessor of gcc (4.1.1). The following macros expand to: #define A(...) __VA_ARGS__ #define B(x,...) __VA_ARGS__ A() -nothing, *no warning* A(x) -x ...
4
by: Max TenEyck Woodbury | last post by:
I need a macro that will take an arbitrarily long list of arguments where each argument needs to be passed to another macro. Is it possible to write such a macro? If so, could you please...
6
by: jason | last post by:
Hi, I learned my lesson about passing pointers, but now I have a question about macros. Why does the function work and the MACRO which is doing the same thing on the surface, does not work in...
16
by: mdh | last post by:
I have asked a few questions about Macros...and think what I have been missing ...and which all who have replied clearly understand...is that this is a Pre-processor action. Hopefully the above is...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.