OK - this tiny program
---------------------
#include <sys/time.h>
main() {
struct tm *tp;
tp = localtime();
tp->tm_isdst;
}
---------------------
generates the following wrning and error
timeq.c: In function main':
timeq.c:8: warning: assignment makes pointer from integer without a cast
timeq.c:9: dereferencing pointer to incomplete type
when compiled on a SuSE 7.3 box with gcc 2.95.3 and glibc 2.2.4
It compiles with no warning or error on a SuSE 6.4 box with gcc 2.95.2 and
libc 2.1.3 (yes, libc, not glibc - seems like a strange libc version number
to me)
While I'm no C whizkid, nor am I C illiterate and I just don't understand
these errors. I have
struct tm *tp;
and according to TFM
struct tm *localtime(const time_t *timep);
so why is my code generating the warning in line 8 ?
And what on earth is an "incomplete type" in line 9 ?
I've had a quick diff of time.h on both boxes and there are big differences
BUT the definition of a struct tm looks about the same AND the relevant bit
of TFM about localtime is the same on each box.
I can get rid of the warning by putting the cast in line 8 as
tp = (struct tm *)localtime();
but why on earth should I have to when localtime IS already a pointer to a
tm struct ? And it still leaves the "incomplete type" error in line 9.
I just tried on a couple of RH boxes I have access to - 6.2 bitches about
too few arguments to localtime but if I remove the localtime call it
compiles so it doesn't seem to regard the struct tm as an incomplete type.
That has egcs-2.91.66 and glibc-2.1.3.
On a Verio box, which claims to be "Verio Enterprise Linux, based on Redhat
Linux 6 & 7", I get the same errors as on SuSE 7.3. That has gcc 2.95.3 and
glibc-2.2.4.
Can some C whizkid please put me out of my misery ?
Niall
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!