Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

pasting "" and "" does not give a valid preprocessing token.

1,908 views
Skip to first unread message

new

unread,
Aug 27, 2009, 8:29:14 PM8/27/09
to
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.

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.

Hans-Bernhard Bröker

unread,
Aug 31, 2009, 8:52:45 AM8/31/09
to
new wrote:

> 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.

Jasen Betts

unread,
Aug 31, 2009, 8:49:51 AM8/31/09
to
On 2009-08-28, new <luvr...@gmail.com> wrote:

> 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;
}

Jyoti Sharma

unread,
Aug 31, 2009, 8:53:08 AM8/31/09
to
On Fri, 28 Aug 2009 05:59:14 +0530, new <luvr...@gmail.com> wrote:

> 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

Keith Thompson

unread,
Sep 3, 2009, 2:46:00 AM9/3/09
to
Jasen Betts <ja...@xnet.co.nz> writes:
[...]

> 2:it is supposed to segfault.
[...]

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"

Dag-Erling Smørgrav

unread,
Sep 3, 2009, 2:45:56 AM9/3/09
to
Jasen Betts <ja...@xnet.co.nz> writes:
> 2:it is supposed to segfault.

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

0 new messages