Thread: inappropriate "initialization makes pointer from integer without a cast" warning

  1. #1
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300

    inappropriate "initialization makes pointer from integer without a cast" warning

    I think I've seen something like this before and someone had an explanation:
    Code:
    #include <time.h>
    #include <stdio.h>
    
    int main() {
    	struct tm *data = getdate("1/1/2010 12 AM");
    	return 0;
    }
    time_convert.c:5: warning: initialization makes pointer from integer without a cast

    From /usr/include/time.h:
    Code:
    extern struct tm *getdate (__const char *__string);
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  2. #2
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    You mean that error occurs if you don't include time.h? In that case, I can explain it (since it's assumed to return an integer since the function isn't declared). Otherwise, I'm not too sure.

  3. #3
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by EVOEx View Post
    You mean that error occurs if you don't include time.h? In that case, I can explain it (since it's assumed to return an integer since the function isn't declared). Otherwise, I'm not too sure.
    I would expect it to happen if I don't include time.h, which is why I highlighted the fact that I did include it
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  4. #4
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    Ah. You'll have to do "#define _XOPEN_SOURCE 500" before including time.h. I'm not sure why this is, though... It's a design choice of the makers of the header files. So there must be a good reason.

  5. #5
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by EVOEx View Post
    Ah. You'll have to do "#define _XOPEN_SOURCE 500" before including time.h. I'm not sure why this is, though... It's a design choice of the makers of the header files. So there must be a good reason.
    That solves the problem, thanks. But what a function this turns out to be:
    Variable: getdate_err

    This variable of type int contains the error code of the last unsuccessful call to getdate. Defined values are:

    1
    The environment variable DATEMSK is not defined or null.

    [...]

    The interface to getdate is the simplest possible for a function to parse a string and return the value. string is the input string and the result is returned in a statically-allocated variable.

    The details about how the string is processed are hidden from the user. In fact, they can be outside the control of the program. Which formats are recognized is controlled by the file named by the environment variable DATEMSK. This file should contain lines of valid format strings which could be passed to strptime.
    So now I have to create some global system file and set an env variable in order to use "the simplest possible for a function to parse a string and return the value"? Grrr...I think I'm going back to the "tricky low level" funcs.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  6. #6
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    Maybe you could use strptime? Not sure if that's better, though. And it needs _XOPEN_SOURCE as well (apparently this is for UNIX compatibility or so...).

  7. #7
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by EVOEx View Post
    Maybe you could use strptime? Not sure if that's better, though. And it needs _XOPEN_SOURCE as well (apparently this is for UNIX compatibility or so...).
    Yeah. Like, OMG:
    Code:
    	struct tm data;
    	strptime("1/1/10 12 AM", "%D %I %p", &data);
    That is too crazy. [Sarcasm] Somebody better write a more user friendly function, like "getdate".
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  2. "assignment makes integer from pointer without a cast"
    By Freez3L in forum C Programming
    Replies: 4
    Last Post: 11-04-2002, 04:26 AM
  3. assignment makes pointer from integer
    By crescen7 in forum C Programming
    Replies: 4
    Last Post: 06-25-2002, 10:08 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 3
    Last Post: 01-14-2002, 12:13 PM