Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
From: dsb@osf.org (David Boyce)
Subject: Re: sprintf problem under OSF/1
Date: 16 Feb 1994 16:54:56 GMT	[thread overview]
Message-ID: <DSB.94Feb16115456@ets7.osf.org> (raw)
In-Reply-To: zagar@names.maricopa.edu's message of 15 Feb 1994 21:49:25 -0700

  >> I'm sorry if I'm asking a common problem, but we just got our first
  >> Alpha and it is driving me crazy.  I have an existing application that
  >> I am trying to port.  I have compiled it with the -taso option, and it
  >> compiles and links without error.  However, when I run it, every time
  >> it encounters simple sprintf errors, it dies with a segmentation
  >> fault.  Does this sound familiar to anyone?  Also, is there any
  >> place that I can find information on what is required to port applications
  >> to OSF/1?

  >> Thanks for any information.

First: as a point of nomenclature, the problem is not with sprintf
under OSF/1, as the subject says.  It's with sprintf on an Alpha, i.e.
it's a 64-bit porting problem.  You'd have the same problem porting
your application to an Alpha running VMS or NT, and you wouldn't have
it porting to another platform running OSF/1.

As for the sprintf problem: the -taso option will only work around the
most common coding-portability mistake, which is assuming a pointer
will fit in an integer and vice versa.  If your code assumes that a
long is the same size as an int, -taso can do nothing about that.  In
particular, when using *printf the following two (incorrect)
constructs will work correctly on a platform where
sizeof(int)==sizeof(long):

	printf("%d", <long>);
	printf("%ld", <int>);

The print routines examine the format string to determine the sizes to
expect for subsequent arguments.  On most machines ints and longs are
both 32 bits and the above, though sloppy, still works.  But on an
Alpha the first printf will be looking for a 32-bit (int-sized)
quantity and get 64, whereas the second will look for 64 and get 32.
I'd guess that your problems come from this.

Take a look at the lint(1) man page on an Alpha and look up the -Q
option.  Pay particular attention to the 'f' suboption.  Running

	lint -Q<everything-but-f> *.[ch]

or similar on your application should show where format string
mismatches occur.
--
David Boyce	dsb@osf.org	617-621-8963


  reply	other threads:[~1994-02-16 16:54 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1994-02-16  4:49 sprintf problem under OSF/1 Chris Zagar
1994-02-16 16:54 ` David Boyce [this message]
1994-02-18  3:42 ` sprintf problem under OSF/1 on Alpha Chris Zagar
1994-02-18 17:48 ` sprintf problem under OSF/1 Andre Beck
read-only archive

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