* _printf_ problem
@ 1996-08-06 14:00 David Wild
0 siblings, 0 replies; 5+ messages in thread
From: David Wild @ 1996-08-06 14:00 UTC (permalink / raw)
I was trying to port a program to my Noname and I kept getting a run time
memory violation error (it compiled fine). I have successfully complied
and ran this on my Intel Linux and Sun Sparc Solaris with no problems.
I finally tracked the problem down to this
time (&t);
printf ("%s\n ", ctime (&t) + 4);
The "+ 4" should move pointer so the output is looks like "Aug 6 08:43:16"
instead of
"Tue Aug 6 08:43:16". Even though it compiles fine it will produce a
memory violation when it gets run. I have never seen this happen on any
other platform.
Does anybody have a clue as to why this is happening.
Dave
"I can fix or break anything; it's leaving stuff alone that I have problems
with..."
--
To unsubscribe: mail -s unsubscribe axp-list-request@redhat.com < /dev/null
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: _printf_ problem
@ 1996-08-06 15:06 David Mosberger-Tang
0 siblings, 0 replies; 5+ messages in thread
From: David Mosberger-Tang @ 1996-08-06 15:06 UTC (permalink / raw)
>>>>> On Tue, 06 Aug 96 10:00:00 EDT, David Wild <dawild@symix.com> said:
David> I finally tracked the problem down to this
David> time (&t); printf ("%s\n ", ctime (&t) + 4);
David> The "+ 4" should move pointer so the output is looks like
David> "Aug 6 08:43:16" instead of "Tue Aug 6 08:43:16". Even
David> though it compiles fine it will produce a memory violation
David> when it gets run. I have never seen this happen on any other
David> platform.
David> Does anybody have a clue as to why this is happening.
Both regular Red Hat 3.0.3 and GNU libc handle this correctly:
$ cat t.c
#include <time.h>
int
main(int argc, char ** argv)
{
time_t t;
time (&t);
printf ("%s\n", ctime (&t) + 4);
}
$ gcc -O2 t.c
$ ./a.out
Aug 6 08:04:55 1996
$
What distribution/libc version are you using?
--david
--
To unsubscribe: mail -s unsubscribe axp-list-request@redhat.com < /dev/null
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: _printf_ problem
@ 1996-08-06 15:25 David Wild
0 siblings, 0 replies; 5+ messages in thread
From: David Wild @ 1996-08-06 15:25 UTC (permalink / raw)
>Both regular Red Hat 3.0.3 and GNU libc handle this correctly:
>What distribution/libc version are you using?
I'm (still) using RH 2.1 and I've never upgraded the libc.
I'll try a newer version.
Thanks
Dave
"I can fix or break anything; it's leaving stuff alone that I have problems
with..."
--
To unsubscribe: mail -s unsubscribe axp-list-request@redhat.com < /dev/null
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: _printf_ problem
[not found] <32075000@msmailgtwy.nvl.symix.com>
@ 1996-08-06 23:37 ` Richard Henderson
0 siblings, 0 replies; 5+ messages in thread
From: Richard Henderson @ 1996-08-06 23:37 UTC (permalink / raw)
> I finally tracked the problem down to this
>
> time (&t);
> printf ("%s\n ", ctime (&t) + 4);
>
> Does anybody have a clue as to why this is happening.
I'd bet a beer you don't include time.h and so get a prototype for ctime().
With no prototype, the compiler, by law, must assume ctime returns an int,
and so the 64-bit pointer gets truncated to 32 bits. gcc -Wall should
warn you about using an integral type where a pointer is expected in the
printf format.
r~
--
To unsubscribe: mail -s unsubscribe axp-list-request@redhat.com < /dev/null
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: _printf_ problem
@ 1996-08-07 12:16 David Wild
0 siblings, 0 replies; 5+ messages in thread
From: David Wild @ 1996-08-07 12:16 UTC (permalink / raw)
I believe I owe you a beer.
That was the solution. I didn't even realize time.h wasn't there.
Thanks again
>> time (&t);
>> printf ("%s\n ", ctime (&t) + 4);
>>
>I'd bet a beer you don't include time.h and so get a prototype for ctime().
>
>With no prototype, the compiler, by law, must assume ctime returns an int,
>and so the 64-bit pointer gets truncated to 32 bits. gcc -Wall should
>warn you about using an integral type where a pointer is expected in the
>printf format.
>
>
>r~
>
--
To unsubscribe: mail -s unsubscribe axp-list-request@redhat.com < /dev/null
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~1996-08-07 12:16 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1996-08-06 14:00 _printf_ problem David Wild
-- strict thread matches above, loose matches on Subject: below --
1996-08-06 15:06 David Mosberger-Tang
1996-08-06 15:25 David Wild
[not found] <32075000@msmailgtwy.nvl.symix.com>
1996-08-06 23:37 ` Richard Henderson
1996-08-07 12:16 David Wild
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox