Linux PARISC architecture development
 help / color / mirror / Atom feed
* [parisc-linux] Building packages, problems with printf
@ 2001-03-25 21:02 Matthew Wilcox
  2001-03-25 23:03 ` Alan Modra
  0 siblings, 1 reply; 6+ messages in thread
From: Matthew Wilcox @ 2001-03-25 21:02 UTC (permalink / raw)
  To: parisc-linux

Something we've been running into when building packages is the problem
that printf is defined as a macro when using gcc 2.97.  This should be
resolved by doing the following:

#include <stdio.h>
#undef printf

fixing glibc to not do that seems to not be an option.  ANSI explicitly
allows any of the functions in libc to also be defined as macros.

-- 
Revolutions do not require corporate support.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [parisc-linux] Building packages, problems with printf
  2001-03-25 21:02 [parisc-linux] Building packages, problems with printf Matthew Wilcox
@ 2001-03-25 23:03 ` Alan Modra
  2001-03-25 23:11   ` Matthew Wilcox
                     ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Alan Modra @ 2001-03-25 23:03 UTC (permalink / raw)
  To: Matthew Wilcox; +Cc: parisc-linux

On Sun, 25 Mar 2001, Matthew Wilcox wrote:

> Something we've been running into when building packages is the problem
> that printf is defined as a macro when using gcc 2.97.  This should be
> resolved by doing the following:
> 
> #include <stdio.h>
> #undef printf

That's cheating!  The real fix is to turn

printf (foo_string,
#if SOMETHING
abc_param
#else
xyz_param
#endif
);

into

#if SOMETHING
printf (foo_string, abc_param);
#else
printf (foo_string, xyz_param);
#endif

Earn brownie points sending off proper fixes to package maintainers. :)

> fixing glibc to not do that seems to not be an option.  ANSI explicitly
> allows any of the functions in libc to also be defined as macros.

Alan
-- 
Linuxcare

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [parisc-linux] Building packages, problems with printf
  2001-03-25 23:03 ` Alan Modra
@ 2001-03-25 23:11   ` Matthew Wilcox
  2001-03-25 23:42   ` Alan Cox
  2001-04-04  1:47   ` Steve Beattie
  2 siblings, 0 replies; 6+ messages in thread
From: Matthew Wilcox @ 2001-03-25 23:11 UTC (permalink / raw)
  To: Alan Modra; +Cc: Matthew Wilcox, parisc-linux

On Mon, Mar 26, 2001 at 09:03:34AM +1000, Alan Modra wrote:
> That's cheating!  The real fix is to turn
> 
> printf (foo_string,
> #if SOMETHING
> abc_param
> #else
> xyz_param
> #endif
> );
> 
> into
> 
> #if SOMETHING
> printf (foo_string, abc_param);
> #else
> printf (foo_string, xyz_param);
> #endif
> 
> Earn brownie points sending off proper fixes to package maintainers. :)

Ah, but that doesn't cure netkit-telnet which is c++ and has a method called
printf which gets royally bollixed by this define.

Agreed that's a better solution though for the cases where it applies.

-- 
Revolutions do not require corporate support.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [parisc-linux] Building packages, problems with printf
  2001-03-25 23:03 ` Alan Modra
  2001-03-25 23:11   ` Matthew Wilcox
@ 2001-03-25 23:42   ` Alan Cox
  2001-03-25 23:44     ` Matthew Wilcox
  2001-04-04  1:47   ` Steve Beattie
  2 siblings, 1 reply; 6+ messages in thread
From: Alan Cox @ 2001-03-25 23:42 UTC (permalink / raw)
  To: Alan Modra; +Cc: Matthew Wilcox, parisc-linux

> Earn brownie points sending off proper fixes to package maintainers. :)

Most package maintainers wont bother. printf as a macro breaks too much code
to be 'interesting' to fix. Many people take the address of printf for 
passing to functions using multiple I/O output methods

> > fixing glibc to not do that seems to not be an option.  ANSI explicitly
> > allows any of the functions in libc to also be defined as macros.

glibc may be ANSI compliant, its just useless if it does this. Useful and
standards compliant  interesect but dont 100% overlap

Alan

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [parisc-linux] Building packages, problems with printf
  2001-03-25 23:42   ` Alan Cox
@ 2001-03-25 23:44     ` Matthew Wilcox
  0 siblings, 0 replies; 6+ messages in thread
From: Matthew Wilcox @ 2001-03-25 23:44 UTC (permalink / raw)
  To: Alan Cox; +Cc: Alan Modra, Matthew Wilcox, parisc-linux

On Mon, Mar 26, 2001 at 12:42:46AM +0100, Alan Cox wrote:
> > Earn brownie points sending off proper fixes to package maintainers. :)
> 
> Most package maintainers wont bother. printf as a macro breaks too much code
> to be 'interesting' to fix. Many people take the address of printf for 
> passing to functions using multiple I/O output methods

you can still do that.  it's still an external function, but for
`optimisation' purposes calls to it go to fprintf.  i think this is a
worthless optimisation myself.

perhaps you can convince drepper of this?  :-)

-- 
Revolutions do not require corporate support.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [parisc-linux] Building packages, problems with printf
  2001-03-25 23:03 ` Alan Modra
  2001-03-25 23:11   ` Matthew Wilcox
  2001-03-25 23:42   ` Alan Cox
@ 2001-04-04  1:47   ` Steve Beattie
  2 siblings, 0 replies; 6+ messages in thread
From: Steve Beattie @ 2001-04-04  1:47 UTC (permalink / raw)
  To: parisc-linux

On Mon, Mar 26, 2001 at 09:03:34AM +1000, Alan Modra wrote:
> On Sun, 25 Mar 2001, Matthew Wilcox wrote:
> 
> > Something we've been running into when building packages is the problem
> > that printf is defined as a macro when using gcc 2.97.  This should be
> > resolved by doing the following:
> > 
> > #include <stdio.h>
> > #undef printf
> 
> That's cheating!  The real fix is to turn
> 
> printf (foo_string,
> #if SOMETHING
> abc_param
> #else
> xyz_param
> #endif
> );
> 
> into
> 
> #if SOMETHING
> printf (foo_string, abc_param);
> #else
> printf (foo_string, xyz_param);
> #endif

Actually, another solution is:

(printf) (foo_string,
#if SOMETHING
abc_param
#else
xyz_param
#endif
);

The parentheses surrounding printf prevent macro expansion -- the C
standard explicitly states that it must. We discovered this in the
course of developing FormatGuard, a patch to glibc that turns printf
and the like into macros as a means of preventing format string attacks
(see http://www.immunix.org/formatguard.html for details).

-- 
Steve Beattie                               Don't trust programmers? 
<steve@wirex.net>                         Complete StackGuard distro at
http://immunix.org/~steve/                         immunix.org

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2001-04-04  1:47 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-03-25 21:02 [parisc-linux] Building packages, problems with printf Matthew Wilcox
2001-03-25 23:03 ` Alan Modra
2001-03-25 23:11   ` Matthew Wilcox
2001-03-25 23:42   ` Alan Cox
2001-03-25 23:44     ` Matthew Wilcox
2001-04-04  1:47   ` Steve Beattie

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox