Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > whats happening here

Reply
Thread Tools

whats happening here

 
 
parag_paul@hotmail.com
Guest
Posts: n/a
 
      03-25-2008
#include <stdio.h>
#define f(a,b) a##b
#define g(a) #a
#define h(a) g(a)

int main()
{
printf("%s\n",h(f(1,2)));
printf("%s\n",g(f(1,2)));
return 0;
}
 
Reply With Quote
 
 
 
 
bdsatish
Guest
Posts: n/a
 
      03-25-2008
On Mar 25, 12:23 pm, "(E-Mail Removed)" <(E-Mail Removed)>
wrote:
> #include <stdio.h>
> #define f(a,b) a##b
> #define g(a) #a
> #define h(a) g(a)
>
> int main()
> {
> printf("%s\n",h(f(1,2)));
> printf("%s\n",g(f(1,2)));
> return 0;
> }


f(1,2) ==> 12 because ## is a concatenating operator, which treats its
inputs a strings. So 1 and 2 are concatenated to form 12

h(a) is simply #a where # is stringisizing operator. So h(12)
becomes the string "12"

Since g(a) is simply #a, the input argument f(1,2) is thrown out as if
it were a string.
 
Reply With Quote
 
 
 
 
parag_paul@hotmail.com
Guest
Posts: n/a
 
      03-25-2008
On Mar 25, 12:43*pm, bdsatish <(E-Mail Removed)> wrote:
> On Mar 25, 12:23 pm, "(E-Mail Removed)" <(E-Mail Removed)>
> wrote:
>
> > #include <stdio.h>
> > * #define f(a,b) a##b
> > * #define g(a) * #a
> > * #define h(a) g(a)

>
> > * int main()
> > * {
> > * * * * * printf("%s\n",h(f(1,2)));
> > * * * * * printf("%s\n",g(f(1,2)));
> > * * * * * return 0;
> > * }

>
> f(1,2) ==> 12 because ## is a concatenating operator, which treats its
> inputs a strings. So 1 and 2 are concatenated to form 12
>
> h(a) is simply #a *where # *is stringisizing operator. So h(12)
> becomes the string "12"
>
> Since g(a) is simply #a, the input argument f(1,2) is thrown out as if
> it were a string.


So what is the order of implemenation.
for h(f(1,2))

f(1,2)
happens first
and in the second case,
g(X)
happens first and then f(1,2)
 
Reply With Quote
 
WANG CONG
Guest
Posts: n/a
 
      03-25-2008
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

> On Mar 25, 12:43*pm, bdsatish <(E-Mail Removed)> wrote:
>> On Mar 25, 12:23 pm, "(E-Mail Removed)" <(E-Mail Removed)>
>> wrote:
>>
>> > #include <stdio.h>
>> > #define f(a,b) a##b
>> > #define g(a) * #a
>> > #define h(a) g(a)

>>
>> > int main()
>> > {
>> > printf("%s\n",h(f(1,2)));
>> > printf("%s\n",g(f(1,2)));
>> > return 0;
>> > }

>>
>> f(1,2) ==> 12 because ## is a concatenating operator, which treats its
>> inputs a strings. So 1 and 2 are concatenated to form 12
>>
>> h(a) is simply #a *where # *is stringisizing operator. So h(12)
>> becomes the string "12"
>>
>> Since g(a) is simply #a, the input argument f(1,2) is thrown out as if
>> it were a string.

>
> So what is the order of implemenation.
> for h(f(1,2))
>
> f(1,2)
> happens first
> and in the second case,
> g(X)
> happens first and then f(1,2)


See Question 11.17 of C FAQ .

http://c-faq.com/ansi/stringize.html

--
Hi, I'm a .signature virus, please copy/paste me to help me spread
all over the world.
 
Reply With Quote
 
Eric Sosman
Guest
Posts: n/a
 
      03-25-2008
bdsatish wrote:
> On Mar 25, 12:23 pm, "(E-Mail Removed)" <(E-Mail Removed)>
> wrote:
>> #include <stdio.h>
>> #define f(a,b) a##b
>> #define g(a) #a
>> #define h(a) g(a)
>>
>> int main()
>> {
>> printf("%s\n",h(f(1,2)));
>> printf("%s\n",g(f(1,2)));
>> return 0;
>> }

>
> f(1,2) ==> 12 because ## is a concatenating operator,


Yes.

> which treats its
> inputs a strings.


No.

See WANG CONG's response.

--
Eric Sosman
(E-Mail Removed)lid
 
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
Basics of VHDL. Whats happening here? vikramtheone VHDL 1 06-01-2009 08:56 PM
"Whats Happening" Computer Program (showed what's running on a PC at a given time): Where To Find ? Robert11 Computer Support 1 12-05-2004 01:51 AM
Whats Happening ???? Lonnie Reynolds Computer Support 1 01-19-2004 01:58 AM
Whats happening to my router? Bryan Martin Cisco 5 01-10-2004 01:23 AM
Whats happening, more probs area 51 Computer Support 0 09-02-2003 05:30 AM



Advertisments