Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 08 Aug 2000 18:34:46 -0400
From:      "Thomas M. Sommers" <tms2@mail.ptd.net>
To:        Alfred Perlstein <bright@wintelcom.net>
Cc:        Mark Ovens <marko@FreeBSD.ORG>, chat@FreeBSD.ORG
Subject:   Re: C time functions - problem
Message-ID:  <39908B06.D1238928@mail.ptd.net>
References:  <20000808201807.H250@parish> <20000808122832.I4854@fw.wintelcom.net>

next in thread | previous in thread | raw e-mail | index | archive | help
Alfred Perlstein wrote:
> 
> * Mark Ovens <marko@FreeBSD.ORG> [000808 12:21] wrote:
> > Can anyone tell me why the call to localtime() in the code below
> > should segfault in tzset()?
> >
> > Running it in the debugger shows that ``t'' is set to a sensible
> > value.
> >
> > Program received signal SIGSEGV, Segmentation fault.
> > 0x280be4c8 in tzset () from /usr/lib/libc.so.4
> >
> >
> > #include <stdio.h>
> > #include <time.h>
> >
> > int main() {
> >       struct tm *timeptr;
> >       char buf[BUFSIZ];
> >       size_t size;
> >       time_t t;
> >
> >       tzset;
> >
> >       t = time((time_t *)0);
> >       timeptr = localtime((time_t *)t);
> >
> >        .....
> 
> Please don't do disgusting things with casts.
> 
> Do not cast a time_t to a time_t *, they aren't the same.
> 
> Don't cast 0 to a pointer type, use NULL.

Or just use 0.



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-chat" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?39908B06.D1238928>