Thread: why i get these warnings..

  1. #1
    Banned
    Join Date
    Oct 2008
    Posts
    1,535

    why i get these warnings..

    warning C4047: 'function' : 'TreeNode *' differs in levels of indirection from 'TreeNode **__w64 '
    warning C4024: 't' : different types for formal and actual parameter 1
    warning C4028: formal parameter 1 different from declaration
    ??
    and i descovered that if i use only one astrix in the signature and i pass
    the pointer instead of &pointer

    then it keeps the changes of the variables in the struct
    if i say p->val=6 then it keeps it
    but if i say p=NULL then it doesnt
    i cant understand why
    p->val is in the variable p
    so it should get the same treatment as p
    ??
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #define false 0
    #define true 1
    
    
    typedef struct TreeNode
    {
    	struct TreeNode *father;
    	struct TreeNode *left;
    	struct TreeNode *right;
    	double val;
    }TreeNode;
    void t(TreeNode* g); 
    int main()
    {
       TreeNode* g;
       g=(TreeNode*)malloc(sizeof(TreeNode));
       g->val=6;
    	t(&g);
    	return 0;
    }
    void t(TreeNode** g)
    {
      *g=NULL;
    }

  2. #2
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    Code:
    void t(TreeNode* g); 
    [...]
    void t(TreeNode** g)
    See the problem yet?

  3. #3
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    It would seem to me that these do not match:
    Code:
    void t(TreeNode* g);
    void t(TreeNode** g) {
    Not sure why you want a pointer to pointer where a pointer would do, either.
    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
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    thanks

    about my second problem
    i descovered that if i use only one astrix in the signature and i pass
    the pointer instead of &pointer

    then it keeps the changes of the variables in the struct
    if i say p->val=6 then it keeps it when we leave the function
    but if i say p=NULL then it doesnt
    i cant understand why
    p->val is in the variable p
    so it should get the same treatment as p
    ??

  5. #5
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by transgalactic2 View Post
    thanks

    about my second problem
    i descovered that if i use only one astrix in the signature and i pass
    the pointer instead of &pointer
    Yes, that's right. &pointer will work if the prototype included **. But for what you are doing, you don't need & or ** unless you want to declare the struct like this:
    Code:
    TreeNode g;   /* no asterisk, g is a struct */
    t(&g);   /* address of struct = pointer */
    instead of like this:
    Code:
       TreeNode* g;
       g=(TreeNode*)malloc(sizeof(TreeNode));
       t(g);   /* no &, g is a pointer (to a struct) */
    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. Warnings when using vector of vector
    By Boksha in forum C++ Programming
    Replies: 5
    Last Post: 03-29-2008, 01:54 PM
  2. Compilers and warnings
    By rogster001 in forum C Programming
    Replies: 6
    Last Post: 03-26-2008, 05:16 AM
  3. Replies: 9
    Last Post: 03-14-2008, 09:55 AM
  4. Warnings from String manipulation functions.
    By Arker in forum C Programming
    Replies: 4
    Last Post: 10-14-2002, 11:59 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM