Warning been displayed

This is a discussion on Warning been displayed within the C Programming forums, part of the General Programming Boards category; Hi; I have this piece of code Code: if((p = getenv("LOCATION")) == NULL) It displays this warning on linux: warning: ...

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    58

    Warning been displayed

    Hi;

    I have this piece of code
    Code:
    if((p = getenv("LOCATION")) == NULL)
    It displays this warning on linux:
    warning: assignment makes pointer from integer without a cast

    How do i get rid of this warning?

    Thanks

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    It means that 'p' is the wrong type (eg: not a pointer to char).

  3. #3
    Registered User
    Join Date
    Aug 2009
    Posts
    58
    but i have it defined as
    Code:
    char *p

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    So that means your compiler thinks getenv returns an int. The reason it thinks so is because you didn't include the header file for getenv.

  5. #5
    Registered User
    Join Date
    Aug 2009
    Posts
    58
    ok that solves my problem for the warning but why didnt that give me a major error and how did it find the getenv function if i didnt include the header??

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by newbie30 View Post
    ok that solves my problem for the warning but why didnt that give me a major error and how did it find the getenv function if i didnt include the header??
    You probably included the library with the code, hence it found the function (assuming you mean it ran successfully) -- since C doesn't do any fancy mangling with types, more or less the right thing happened (basically: the string was put on the stack just in case; that's what the function expected, so it ran successfully; and since your architecture apparently has the same size ints as char *s, the return value didn't get mangled either).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 10
    Last Post: 07-10-2008, 04:45 PM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  3. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 06:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21