This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Projects for beginners


 > From: Neil Booth <neil@daikokuya.demon.co.uk>
 > 
 > Kaveh R. Ghazi wrote:-
 > 
 > > 1.  Is this (within reason) possible?
 > 
 > Certainly.
 > 
 > > 2.  Do ya'll think it's worthwhile?
 > 
 > Not really.  We have enough historical baggage in CPP as it is.
 > Neil.

Fair enough.

But in the mean time, as I toyed with implementing it myself, I
realized that the current "poison" behaves exactly as I wanted for the
new feature.  Apparently Zack's description about it triggering on
macros was wrong.

E.g. try compiling the following with the latest sources.

----cut here----
extern void *malloc(__SIZE_TYPE__);
#define memcpy bcopy
#define strdup(x) strcpy(malloc(strlen(x)+1), x) /* e.g. */

#pragma GCC poison bcopy malloc

void foo(void)
{
  char foo[20], bar[20];
  int baz = sizeof(foo);

  strdup(foo);
  memcpy(foo, bar, baz);

  bcopy(foo, bar, baz);
  malloc(baz);

#define memcpy bcopy
}
----cut here----
I get:

foo.c:15:3: attempt to use poisoned "bcopy"
foo.c:16:3: attempt to use poisoned "malloc"
foo.c:18:16: attempt to use poisoned "bcopy"

I.e. no warnings for calling strdup or memcpy whose definition contain
the poisoned tokens!

Now is this a bug or a feature? :-)

		--Kaveh
--
Kaveh R. Ghazi			Engagement Manager / Project Services
ghazi@caip.rutgers.edu		Qwest Internet Solutions


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]