|
toxcct wrote: BTW, please do the same to me
Done buddy!
But you understand that it cannot be our voting guideline unless we want to be hounded out CP for violating the Competition Law.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
hey, we're not enforcing anything. we're just reacting to G_G voting bad habit.
we're all good guyz here, so what's bad in this ?! lol.
|
|
|
|
|
the , operator returns the last of its statements.
here, the macro calls the Foo function, to which the counter variable is passes by pointer (so, the counter variable is modified from within the Foo() function, but its modifications are still visible from the caller).
then, the counter variable is return (and as there is no = operator in the instruction GETFOO; , the returned value is not used, but still the counter variable is assigned with 100.
writing GETFOO; here is as if you were doing Foo(&counter);
BTW, this is very awful coding, and you should never use such macros !
and to finish, a question: how old are you ?
modified on Wednesday, December 12, 2007 8:01:42 AM
|
|
|
|
|
Thanks toxcct,
I do not agree with your answer. What do you mean class Foo? I am not using any object related concepts and techniques. It is pure C code.
regards,
George
|
|
|
|
|
George_George wrote: I do not agree with your answer
don't say you don't agree, just say you don't understand.
now,
1) my answer was plainly explaining what the macro was doing, i just confused class with function, but the bahavior is the same,
3) my post deserves more than what you gave it,
4) you didn't answer my F*CKING QUESTION,
5) ...
|
|
|
|
|
He didn't answer your question so you should vote him a 2 or 1
|
|
|
|
|
totally right. all fixed Sir.
|
|
|
|
|
Thanks toxcct,
Cool!
regards,
George
|
|
|
|
|
George_George wrote: Thanks toxcct,
about what ?
|
|
|
|
|
This is an odd macro, but I presume it makes more sense in the context you're copying it from. (after all, if you wrote it yourself, you'd know what it does.
It may make more sense if main was like this
main ()
{
int q = GETFOO;
return 0;
}
instead.
That is expanded to...
int q = Foo(&counter), counter;
So, the function Foo is called, does it's magic, and places a result into counter.
Then the second half of the right hand expression is called, which is simply counter, so counter is then placed into q .
It's equivalent to:
int q;
Foo (&counter);
q = counter;
The comma operator is a bit odd and will take some reading.
The main place I see it is in for loops:
for (a = 0, b = 7; a < 9; a++, b++)
{
...
}
while allows you to combine a bunch of expressions between the ;'s.
I hope that makes some sense.
While you're asking us all the horrible questions in C, I can't recommend strongly enough The C Programming Language[^] by Kernighan & Ritchie.
Iain.
|
|
|
|
|
Iain Clarke wrote: The main place I see it is in for loops:
for (a = 0, b = 7; a < 9; a++, b++)
{
...
}
I saw it also in the following kind of stuff
int i,j,k;
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Thanks CPallini,
My question is,
I think using in my sample,
#define GETFOO (Foo( &counter ), counter)
is the same as
#define GETFOO Foo( &counter )
So, no benefits of using , operator, right?
regards,
George
|
|
|
|
|
George_George wrote: So, no benefits of using , operator, right?
yes there is !!! and i explained you why in my first answer.
if you were writing this:
#define GETFOO (Foo(&counter), counter)
void Foo(int* i) {
&i = 100;
}
void main() {
int counter;
int i2 = GETFOO;
}
with the macro not containing the sequence operator ( , ), it would not even compile, because the Foo() function here is ot type void .
here is another example of how it could be used:
void main() {
int counter;
int i2 = (GETFOO * 5);
}
|
|
|
|
|
Cool toxcct!
My question is answered.
regards,
George
|
|
|
|
|
George_George wrote: My question is answered.
so answer mine[^] now
|
|
|
|
|
Geez, why did you get down voted on that one ? It seems that you cannot even participate to a discussion without being downvoted if you don't answer to the original question...
|
|
|
|
|
yup, exactly ([edit]I thought you were replying to G_G, not CPallini[/Edit]. i countervoted the 1 vote with 5 to CPallini).
a forum is living with the participation of everyone.
if the only thing G_G can do is asking his crap with never answering the questions (so simples are they moreover) we do ask him, why should we make him gifts...?!
but the worst is that he doesn't even understand what he does and what he gets !!!!
|
|
|
|
|
Uhhh, for a while, I was a friendly fire victim.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Cedric Moonen wrote: Geez, why did you get down voted on that one ?
In fact, I don't know.
IMHO my post had not to be voted at all. It was a simple note.
Anyway I don't care a lot about.
I'm getting very angry whenever someone votes 1 my technical answer without replying to: if I made some bad mistake then I have to know about; if the voter has a very different point of view about the argument then maybe interesting to debate a bit.
Anyway, thank you very much for your post.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Hmm, that needs a well reasoned, logical, mature reply...
Phhhbbbbbt!
Iain.
|
|
|
|
|
Thanks Iain,
My question is,
I think using in my sample,
#define GETFOO (Foo( &counter ), counter)
is the same as
#define GETFOO Foo( &counter )
So, no benefits of using , operator, right?
regards,
George
|
|
|
|
|
George,
I have to say, that some of your questions are pretty interesting, and I read the threads because I learn as well. But something that I don't understand...
If you ask how does it works, and you get a explanation...
If you ask for an example of practical use, and you get an explanation...
If you ask for... and you get an explanation...
WHY THE HELL DO YOU SAY YOU ARE NOT AGREE AND REASK ANOTHER TIME THE SAME to any other person that is writing in the thread, altough the question has been answered 2 or 3 times (but it seems that you don't like the answers)?
I guess (from the questions you made) you should be more skilled than me. But man... I can not understand it. Looking in your secondary/third questions about the same thing (or something derived) it seems that you are unable to get the contents you are answered with.
Sorry if I seem a bit rude, I have no intention to offend you.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
|
|
|
|
|
amen (and 5 for this !)
|
|
|
|
|
I'll refer you to my previous answer, where I spell out the use & benefit of it. Or to toxcct's.
Iain.
|
|
|
|
|
Are you confused by the comma (a.k.a., sequential-evaluation) operator?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|