#define FF(x,b) { \
struct ret *t; \
t->##x = b; \
}
struct ret {
int *a;
};
int main()
{
int y =10,*g;
struct ret *s;
g =&y;
FF(a,g);
printf("val:%x %x\n",s->a,g);
return 0;
}
---------------
When I compile I get the following error:
field.c:17:1: pasting "->" and "a" does not give a valid preprocessing
token
I tried removing the ##,it compiled succesfully but I think doesnt
solve my purpose.
Can anyone please help in getting rid of this error? Am I missing
something here?
gcc version 3.4.6 20060404 (Red Hat 3.4.6-9)
Thanks in adv.
-- 
comp.lang.c.moderated - moderation address: cl...@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line.  Sorry.
> I tried removing the ##,it compiled succesfully but I think doesnt
> solve my purpose.
Well, you think incorrectly.  There's absolutely no point using the ## 
operator in that macro, and the compiler rightly informed you of that.
> When I compile I get the following error:
> field.c:17:1: pasting "->" and "a" does not give a valid preprocessing
> token
1:why are you pasting ?
2:it is supposed to segfault.
try it like this:
#include<stdio.h>
#define FF(x,b) { \
s->x = b; \
}
struct ret {
int *a;
};
int main()
{
  int y =10,*g;
  struct ret m,*s=&m;
  g =&y; 
  FF(a,g);
  printf("val:%p %p\n",s->a,g);
  return 0;
}
> Hi all,
> I have a program as below:
> -----------
> #include<stdio.h>
>
> #define FF(x,b) { \
> struct ret *t; \
> t->##x = b; \
> }
>
> struct ret {
> int *a;
> };
> int main()
> {
> int y =10,*g;
> struct ret *s;
> g =&y;
> FF(a,g);
> printf("val:%x %x\n",s->a,g);
> return 0;
> }
> ---------------
> When I compile I get the following error:
> field.c:17:1: pasting "->" and "a" does not give a valid preprocessing
> token
>
> I tried removing the ##,it compiled succesfully but I think doesnt
> solve my purpose.
>
I think you have not understood the use and purpose of the Token-Pasting  
Operator.
These links might be of help:
http://msdn.microsoft.com/en-us/library/09dwwt6y(VS.80).aspx
http://www.keil.com/support/man/docs/c166/c166_pp_tokenpastingop.htm
Regards,
Jyoti
Nothing is ever *supposed* to segfault as far as the C standard is
concerned.  In the situation here (dereferencing an uninitialized
pointer), the behavior is undefined.  A segfault, assuming such a
thing exists on the target system, is just one of an unlimited number
of possibilities -- including quietly behaving as you'd expect.
-- 
Keith Thompson (The_Other_Keith) ks...@mib.org  <http://www.ghoti.net/~kst>
Nokia
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
No, it is not supposed to segfault.  Nothing is ever *supposed* to
segfault.  The standard *allows* the implementation to do whatever it
wants under certain circumstances; this may or may not include
segfaulting, on systems where that word has a meaning.
DES
-- 
Dag-Erling Smørgrav - d...@des.no