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

how the macro works

Hello everyone,
I can not understand how the following code works and assign 100 to
counter variable?

Expand|Select|Wrap|Line Numbers
  1. void Foo (int* input)
  2. {
  3. *input = 100;
  4.  
  5. return;
  6. }
  7.  
  8. #define GETFOO  (Foo( &counter ), counter)
  9.  
  10. int counter;
  11.  
  12. int main()
  13. {
  14. GETFOO;
  15. return 0;
  16. }
  17.  

thanks in advance,
George
Dec 12 '07 #1
18 1672
George2 said:
Hello everyone,
I can not understand how the following code works and assign 100 to
counter variable?

void Foo (int* input)
{
*input = 100;

return;
}

#define GETFOO (Foo( &counter ), counter)

int counter;

int main()
{
GETFOO;
return 0;
}
After macro replacements have occurred, your program becomes:

void Foo (int* input)
{
*input = 100;

return;
}
int counter;

int main()
{
(Foo( &counter ), counter);
return 0;
}

Now that you see it like that, does it strike you as being a bit weird?
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Dec 12 '07 #2
George2 <ge*************@yahoo.comwrote in news:c0f8e56c-9fb3-40d6-a504-
72**********@s12g2000prg.googlegroups.com:
I can not understand how the following code works and assign 100 to
counter variable?

My guess is you don't know how the comma operator works.

It takes two operands, a left one and a right one.

It evaluates the left operand, then evaluates the right operand, and the
resulting expression is equal to the right operand. (I can't remember if
you can use it as an L-value, but my guess would be no).

If you have:

y = Func(), 5;
then it's as if you wrote:

Func();

y = 5;

That is: "Func()" gets evaluated, then "5" gets evaluated, and the
resultant expression is "5".
--
Tomás Ó hÉilidhe
Dec 12 '07 #3
Tomás Ó hÉilidhe wrote:

(Those are funny characters in the name.)
George2 <ge*************@yahoo.comwrote in news:c0f8e56c-9fb3-40d6-a504-
72**********@s12g2000prg.googlegroups.com:
>I can not understand how the following code works and assign 100 to
counter variable?

My guess is you don't know how the comma operator works.

It takes two operands, a left one and a right one.

It evaluates the left operand, then evaluates the right operand, and the
resulting expression is equal to the right operand. (I can't remember if
you can use it as an L-value, but my guess would be no).
So far, so good, but:
If you have:

y = Func(), 5;

then it's as if you wrote:

Func();

y = 5;
No; it's as though you'd written

y = Func(); 5;

Comma is the least binding operator (when it's an operator at all).

Example code:

#include <stdio.h>

int func(void)
{ return 17; }

int main(void)
{
int y;
y = func(), 5;
fprintf( stderr, "y == %d\n", y );
return 0;
}

Output:

y == 17

--
Chris "an operator of unspecified precedence" Dollin

Hewlett-Packard Limited Cain Road, Bracknell, registered no:
registered office: Berks RG12 1HN 690597 England

Dec 12 '07 #4
Chris Dollin <ch**********@hp.comwrote in
news:fj**********@tadcaster.hpl.hp.com:
No; it's as though you'd written

y = Func(); 5;

Comma is the least binding operator (when it's an operator at all).

Wups a daisy, I should laminate an operator precedence table and blue-tack
it to my laptop :-D.

--
Tomás Ó hÉilidhe
Dec 12 '07 #5
Tomás Ó hÉilidhe wrote:
Chris Dollin <ch**********@hp.comwrote in
news:fj**********@tadcaster.hpl.hp.com:
>No; it's as though you'd written

y = Func(); 5;

Comma is the least binding operator (when it's an operator at all).


Wups a daisy, I should laminate an operator precedence table and blue-tack
it to my laptop :-D.
Or test your assertions with a program...
Dec 12 '07 #6
Example code:
>
#include <stdio.h>

int func(void)
{ return 17; }

int main(void)
{
int y;
y = func(), 5;
fprintf( stderr, "y == %d\n", y );
return 0;
}

Output:

y == 17
get the right operand like this:
y = (func(), 5);

the Output is: y==5
Dec 12 '07 #7
Chris Dollin wrote:
Tom�s � h�ilidhe wrote:

(Those are funny characters in the name.)
Not as funny as they appear to me:
"Tomï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï ¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ " wrote:
Dec 12 '07 #8
Philip Potter <pg*@doc.ic.ac.ukwrote in news:fj**********@aioe.org:
Chris Dollin wrote:
>Tom�s � h�ilidhe wrote:

(Those are funny characters in the name.)

Not as funny as they appear to me:
"Tomï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï ¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï
¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½" wrote:


Do you not use UTF-8 in your newsreader?

--
Tomás Ó hÉilidhe
Dec 12 '07 #9
"Tomï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï ¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ " wrote:
Philip Potter <pg*@doc.ic.ac.ukwrote in news:fj**********@aioe.org:
>Chris Dollin wrote:
>>Tom�s � h�ilidhe wrote:

(Those are funny characters in the name.)
Not as funny as they appear to me:
"Tom�������½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿ ½Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½Ã¯Â¿Â½Ã¯
¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï ¿Â½Ã¯Â¿Â½" wrote:

Do you not use UTF-8 in your newsreader?
The important thing is that you do not set a character encoding in your
headers. For example:

Content-Type: text/plain; charset=utf-8

If you don't provide this information, my newsreader cannot magically
know which character set you're using; and you have no reason to expect
it to default to UTF-8 because I might meet someone else who expects it
to default to ISO-8859-1.

As a matter of fact I do use UTF-8 as default. If I change it to
ISO-8859-1 then I get "Tomás Ó hÉilidhe wrote:" which looks more likely.
So it seems you aren't using UTF-8 at all, but one of the ISO-8859 family.

Unfortunately, I don't have any advice for you on how to rectify the
situation because I use a different newsreader. Nevertheless, I wish you
the best of luck fixing it.

Phil
Dec 12 '07 #10
Philip Potter <pg*@doc.ic.ac.ukwrote in news:fj**********@aioe.org:
The important thing is that you do not set a character encoding in
your headers. For example:

Content-Type: text/plain; charset=utf-8

If you don't provide this information, my newsreader cannot magically
know which character set you're using; and you have no reason to
expect it to default to UTF-8 because I might meet someone else who
expects it to default to ISO-8859-1.

As a matter of fact I do use UTF-8 as default. If I change it to
ISO-8859-1 then I get "Tomás Ó hÉilidhe wrote:" which looks more
likely. So it seems you aren't using UTF-8 at all, but one of the
ISO-8859 family.

Unfortunately, I don't have any advice for you on how to rectify the
situation because I use a different newsreader. Nevertheless, I wish
you the best of luck fixing it.

I started out using a Linux newsreader called Pan, but it turned out to be
crap.

At the moment I'm using a Windows newsreader called XNews, which is
supposedly the best newsreader ever (or so say the people who recommended
it to me). I wouldn't have thought that XNews got it wrong when it came to
character encoding. . . ?

--
Tomás Ó hÉilidhe
Dec 12 '07 #11
"Tomás Ó hÉilidhe" <to*@lavabit.comwrites:
Philip Potter <pg*@doc.ic.ac.ukwrote in news:fj**********@aioe.org:
>The important thing is that you do not set a character encoding in
your headers.
<snip>
I started out using a Linux newsreader called Pan, but it turned out to be
crap.

At the moment I'm using a Windows newsreader called XNews, which is
supposedly the best newsreader ever (or so say the people who recommended
it to me). I wouldn't have thought that XNews got it wrong when it came to
character encoding. . . ?
I would not have thought so either, but your postings arrive here with
no encoding specified and characters outside the safe 7-bit range.
There is probably an XNews group or mailing list where you can ask
about fixing this.

--
Ben.
Dec 12 '07 #12
Philip Potter <pg*@doc.ic.ac.ukwrote:
"Tomï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï ¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ " wrote:
Philip Potter <pg*@doc.ic.ac.ukwrote in news:fj**********@aioe.org:
Chris Dollin wrote:
Tom�s � h�ilidhe wrote:

(Those are funny characters in the name.)
Not as funny as they appear to me:
"Tomï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿ ½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ ������ï
¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿ ½ï¿½" wrote:
Do you not use UTF-8 in your newsreader?

The important thing is that you do not set a character encoding in your
headers. For example:
The most important thing is that, Welshmen and Friesians
notwithstanding, Usenet is still a 7-bit medium, and those who assume
otherwise do so at their own peril, and at the peril of their names'
spelling.

Richard
Dec 13 '07 #13
"Tomï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï ¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ " wrote:
Philip Potter <pg*@doc.ic.ac.ukwrote in news:fj**********@aioe.org:
>The important thing is that you do not set a character encoding in
your headers. For example:

Content-Type: text/plain; charset=utf-8

If you don't provide this information, my newsreader cannot magically
know which character set you're using; and you have no reason to
expect it to default to UTF-8 because I might meet someone else who
expects it to default to ISO-8859-1.

As a matter of fact I do use UTF-8 as default. If I change it to
ISO-8859-1 then I get "Tomás Ó hÉilidhe wrote:" which looks more
likely. So it seems you aren't using UTF-8 at all, but one of the
ISO-8859 family.

Unfortunately, I don't have any advice for you on how to rectify the
situation because I use a different newsreader. Nevertheless, I wish
you the best of luck fixing it.

I started out using a Linux newsreader called Pan, but it turned out to be
crap.

At the moment I'm using a Windows newsreader called XNews, which is
supposedly the best newsreader ever (or so say the people who recommended
it to me). I wouldn't have thought that XNews got it wrong when it came to
character encoding. . . ?
It seems that they did. Appealing to reputation can be useful, but it
doesn't trump the evidence of your postings. Have a look at the full
headers yourself - notice that most people here will declare a charset
in their headers, especially if they want to use non-ASCII characters
like ᩲ‡. A quick google for "xnews charset" turned up this:

http://tinyurl.com/ypfygj

which seems to show that XNews' creator considers the software to be
aimed at himself only, and isn't interested in catering to things he
isn't interested in. It seems character sets is one of those things.

There is also a link on that page to a tool which claims to fix this
problem in XNews.

Phil
Dec 13 '07 #14
Philip Potter <pg*@doc.ic.ac.ukwrote in comp.lang.c:
The important thing is that you do not set a character encoding in
your headers. For example:

Content-Type: text/plain; charset=utf-8

I manually went into my XNews settings and added "custom headers".

How does this post look?

--
Tomás Ó hÉilidhe
Dec 13 '07 #15
"Tomás Ó hÉilidhe" <to*@lavabit.comwrote in comp.lang.c:

I manually went into my XNews settings and added "custom headers".

How does this post look?

Damn, looks like I didn't enable the new settings.
How does this post look?
--
Tomás Ó hÉilidhe
Dec 13 '07 #16
"Tomï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï ¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ " wrote:
Philip Potter <pg*@doc.ic.ac.ukwrote in comp.lang.c:
>The important thing is that you do not set a character encoding in
your headers. For example:

Content-Type: text/plain; charset=utf-8


I manually went into my XNews settings and added "custom headers".

How does this post look?
Can't you see for yourself? Find the option in XNews to display all headers.

In any case, I think the above attribution line speaks for itself.

Incidentally, your sig comes out as:
Tomás Ó hÉilidhe
which is fine. It seems your message body is UTF-8 but your header is
ISO-whatever-it-is. This is not a good situation.
Dec 13 '07 #17
"Tomás Ó hÉilidhe" <to*@lavabit.comwrites:

Dec 13 '07 #18
On Wed, 12 Dec 2007 17:16:53 +0000, Philip Potter <pg*@doc.ic.ac.uk>
wrote:
"Tom????????????????????????????????" wrote:
Philip Potter <pg*@doc.ic.ac.ukwrote in news:fj**********@aioe.org:
Chris Dollin wrote:
Tom�s � h�ilidhe wrote:

(Those are funny characters in the name.)
Do you not use UTF-8 in your newsreader?

The important thing is that you do not set a character encoding in your
headers. For example:

Content-Type: text/plain; charset=utf-8
Or 8859 or whatever. But that applies to the (single-part) BODY.
The correct way to use non-7-bit-ASCII IN HEADERS, in particular the
'From:' header, is =?cset?Q?qp?= or =?cset?B?b64?= per RFC 2047.

It's probably possible to configure this by hand if your program can't
(or won't) be fixed; alternatively the OP might consider just using
the (ASCII) address and an ASCII-compatible nickname, with the real
name in the sig -- which at protocol level is in the body, as above.
Or if there is an acceptable ASCII transliteration of the name.

- formerly david.thompson1 || achar(64) || worldnet.att.net
Dec 24 '07 #19

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

Similar topics

1
by: alon | last post by:
i am using access 2000 .when i use macro and in the macro use msgbox the access stuck , the other software in the computer works great , and the same database with the same macro at other computer...
0
by: Jim Caddy | last post by:
Hi all, I have an Autokeys Macro that's all in a sudden not working in access 2000 when pressing the key combinations. Open up the database in Access 2002 and the macro works, reopen the...
1
by: Patrick_Montana | last post by:
I am having a problem auto-activating a macro when I change data in a field on a form that is a combo box. I have a fair understanding of Microsoft Access but am not a programmer so I am trying to...
6
by: geronimo_me | last post by:
Hi, I am trying to run an Excel macro from an Access module, however when I run the code the macro runs but then I get an error in Access. The error is: Run-time error "440", Automation error. ...
10
by: Karim Thapa | last post by:
Why following macro does not work? #define removebrace(x) x void Foo(int a, int b, char *txt, int d, int e); main() {
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...
20
by: rkk | last post by:
Hi, Is there an equivalent typeof macro/method to determine the type of a variable in runtime & most importantly that works well with most known C compilers? gcc compiler supports typeof()...
5
by: martin.brodeur | last post by:
I unable to pass a template type with two parameters to a very simple macro with g++ 3.4 (Linux x86): for example: #define THIS_IS_A_MACRO(token) BOOST_PP_STRINGIZE(token) void foo() {...
34
by: Umesh | last post by:
how to convert a program to a function/macro and put it in a header file? is there any shortcut method for this? thanks.
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
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...

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.