Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

assignment makes pointer from integer without cast 1

Status
Not open for further replies.

Shay2501

MIS
Jun 25, 2003
24
0
0
US
I am working on a program for school and although this is just a warning, I would like it to go away.

Basically, I have a function that returns a pointer to a struct called symrec. However, when I try to assign this return to another symrec pointer, I get the above error. Here is a sample:

struct symrec *s;

s=putsym(sym_name);

/*here is putsym function */

symrec * putsym(const char *sym_name, int sym_type){
symrec *ptr;

/*create new space from heap for new symrec*/
ptr = (symrec *) malloc (sizeof (symrec));

/*allocate space for the name of the symbol*/
ptr->name = (char *) malloc (strlen(sym_name) + 1);

/*assign the name of the symrec*/
strcpy (ptr->name,sym_name);

/*assign type to the symrec*/
ptr->type = sym_type;

/* Set value to 0 even if fctn. */
ptr->value.var = 0;

/*insert it into the beginning of the symbol table*/
ptr->next = (struct symrec *)sym_table;

/*assign the sym_table to point to the new head of the table*/
sym_table = ptr;

return ptr;
}

Any ideas how I can fix the error?

Thanks in advance.
 
1. Always use CODE tag for your snippets (see Process TGML link on the form).
2. The putsym function signature is
Code:
struct symrec * putsym(const char *sym_name, int sym_type);
But you call putsym(sym_name) - why? Where is the 2nd argument?
Add putsym prototype before the function call. Probably, in your casse the C compiler does not know about return value type (int by default in C). Or place this (all) function definition (textually) before the 1st call.
3. You have C/C++ struct reference mixture in your snippet. Use struct symrec in C, or declare type alias:
Code:
typedef struct symrec* SymPtr;
 
Thanks for your help. The problem was not including the function prototype in the file that called the function.

The putsym(sym_name) was a typo, I just didn't add the other argument. I have the typedef for symrec included in my code, again I just didn't paste that here. Thanks for pointing out the CODE tags as well. I posted this late last night in frustration, please forgive me for my newbie mistatkes ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top