This is the mail archive of the gcc-patches@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: Prevent macro expansion of mblen


Alexandre Oliva <aoliva@redhat.com> writes:

| [1  <text/plain>]
| On Dec 22, 2000, Benjamin Kosnik <bkoz@redhat.com> wrote:
| 
| >> IRIX 5.2's stdlib.h defines mblen as a macro.  I wonder whether we
| >> should just #ifdef the declaration out in this case, or define
| >> std::(mblen) as an inline function that expands the macro, or do as
| >> the patch below (mblen is available as a function, despite the
| >> existence of the macro).
| 
| > Hmm. Not ok to install. Of the options you presented, making an inline 
| > function that expands the macro and then undefs the define is preferred.
| 
| Indeed.  Here's a revised patch.  Ok to install?

I afraid: No.

| +#ifdef mblen
| +  inline int (mblen)(const char *p, size_t l) { return mblen(p, l); }
| +#undef mblen
| +#else
|    extern "C" int mblen(const char*, size_t); 
| +#endif

"mblen" needs to have C linkage in all cases.

The easiest way to go is along something like

#ifdef mblen

	inline int __mblen_capture(const char* p, size_t l)
	{ return mblen(p, l); }
#  undef mblen
	extern "C" inline int mblen(const char* p, size_t l)
	{ return __mblen_capture(p, l); }
#else
	extern "C" int mblen(const char*, size_t);
#endif

-- Gaby
CodeSourcery, LLC                       http://www.codesourcery.com

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