Thread: ' assignment makes pointer from integer without a cast "

  1. #1
    Registered User
    Join Date
    May 2008
    Location
    India
    Posts
    30

    ' assignment makes pointer from integer without a cast "

    Hi All,
    Greeting!
    I am getting this error " assignment makes pointer from integer without a cast" for this line.

    Code:
    root=addtree(root,job);
    Declaration for addtree is as follows
    Code:
    Tree_ptr addtree(Tree_ptr ,char *);
    and Tree_ptr is
    Code:
    typedef struct tree_node
    {
    	char *word;
    	int index;
    	struct tree_node *left;
    	struct tree_node *right;
    }Tree;
    
    typedef struct tree_node *Tree_ptr;
    .

    and Declaration for root is
    Code:
    Tree_ptr root;
    The whole point is to return a pointer to a structure tree_node. I am just trying to learn typedef. Could some one please explain what is wrong with this declaration?

  2. #2
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    hmm, compiling on linux with command and options "gcc str.c -Wall -pedantic" gives no errors or warnings. this is what i am compiling, of course based on your code snippets:
    Code:
    typedef struct tree_node
    {
    	char *word;
    	int index;
    	struct tree_node *left;
    	struct tree_node *right;
    }Tree;
    
    typedef struct tree_node *Tree_ptr;
    
    Tree_ptr addtree(Tree_ptr ,char *);
    
    int main()
    {
        char * job;
        Tree_ptr root;
        root=addtree(root,job);
        return 1;
    
    }
    
    Tree_ptr addtree(Tree_ptr a,char *b){
        return a;
    }
    is "job" of correct type? what compiler are you using?

  3. #3
    Registered User
    Join Date
    May 2008
    Location
    India
    Posts
    30
    Quote Originally Posted by nadroj View Post
    hmm, compiling on linux with command and options "gcc str.c -Wall -pedantic" gives no errors or warnings. this is what i am compiling, of course based on your code snippets:
    Code:
    typedef struct tree_node
    {
    	char *word;
    	int index;
    	struct tree_node *left;
    	struct tree_node *right;
    }Tree;
    
    typedef struct tree_node *Tree_ptr;
    
    Tree_ptr addtree(Tree_ptr ,char *);
    
    int main()
    {
        char * job;
        Tree_ptr root;
        root=addtree(root,job);
        return 1;
    
    }
    
    Tree_ptr addtree(Tree_ptr a,char *b){
        return a;
    }
    is "job" of correct type? what compiler are you using?
    I am using gcc. Your code doesn't give me any error or warning.. Job is char *. Let me see what is wrong with mine.

  4. #4
    Registered User
    Join Date
    Sep 2007
    Posts
    1,012
    One possibility is that you're using addtree() without declaring it; that is, you forgot to include whatever header contains a prototype for it. In the absence of a declaration, the compiler will assume the function returns int, and you'd get the message you describe above.

    While it's technically legal to use (some) functions before declaring them, such uses should always be considered bugs, and fixed. GCC will tell you about such implicit declarations if you use the -Wall flag. Really, you should always, always, always build with at least the -Wall flag, as it will alert you to all sorts of potential problems.

  5. #5
    Registered User
    Join Date
    May 2008
    Location
    India
    Posts
    30
    Quote Originally Posted by cas View Post
    One possibility is that you're using addtree() without declaring it; that is, you forgot to include whatever header contains a prototype for it. In the absence of a declaration, the compiler will assume the function returns int, and you'd get the message you describe above.

    While it's technically legal to use (some) functions before declaring them, such uses should always be considered bugs, and fixed. GCC will tell you about such implicit declarations if you use the -Wall flag. Really, you should always, always, always build with at least the -Wall flag, as it will alert you to all sorts of potential problems.
    Thanks!
    Yes, You are right. I missed the function declaration in the header file.
    Thanks to all for their kind help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. warning: cast to pointer from integer of different size
    By DavidDobson in forum C Programming
    Replies: 6
    Last Post: 12-03-2008, 06:37 PM
  2. pointers, structures, and malloc
    By lugnut in forum C Programming
    Replies: 24
    Last Post: 10-09-2008, 04:52 PM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. assignment makes pointer from integer
    By crescen7 in forum C Programming
    Replies: 4
    Last Post: 06-25-2002, 10:08 PM
  5. Replies: 3
    Last Post: 01-14-2002, 12:13 PM