473,385 Members | 2,003 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Return from incompatible pointer type

/*
* symboltable.c
*
* Created on: Apr 3, 2012
* Author: NA
*/

#include "symboltable.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "include/utlist.h"
#include<conio.h>

symbol *symtable = NULL;
symbol *currentScope = NULL;


void pushVar(char *name) {
struct symbol *s = NULL;
s = (struct symbol*)malloc(sizeof(struct symbol));
s->name = (char *) malloc (strlen (name) + 1);
s->name = name;
s->type = 1;
if(currentScope!=NULL){
s->var.scope=currentScope;
printf("identified a variable \"%s\" in the scope of function \"%s\"\n",s->name,s->var.scope->name);
}
else printf("identified a global variable \"%s\"\n",s->name);

if(currentScope==NULL)
if(!exists_Sym_glob(name)){
printf("appending symbol \"%s\" to global symboltable \n",name);
printf("-----------------------------------------------------------------\n");
LL_APPEND(symtable,s);
}
else return;
else if(!exists_Sym_loc(name)){
printf("appending symbol \"%s\" to local table \"%s\" \n",name,currentScope->name);
printf("-----------------------------------------------------------------\n");
LL_APPEND(currentScope,s);
}
}

void pushFunc(int type, char *name){
struct symbol *s = NULL;
s = (struct symbol*)malloc(sizeof(struct symbol));
s->name = (char *) malloc (strlen (name) + 1);
s->name = name;
s->type = type;
printf("identified function %s of type %d\n",s->name,s->type);

if(!exists_Sym_glob(name)){
LL_APPEND(symtable,s);
printf("appending function %s to global table \n",name);
printf("-----------------------------------------------------------------\n");
}

currentScope = s;
printf("set current scope to %s\n",currentScope->name);
printf("-----------------------------------------------------------------\n");

}

void resetScope(){
currentScope=NULL;
printf("reset scope to global\n");
printf("-----------------------------------------------------------------\n");
}

int exists_Sym_glob(char *name){
symbol *s = NULL;
printf("searching for symbol \"%s\" in global table\n",name);
if(symtable == NULL){
printf("global symboltable is empty\n");
return 0;
}

LL_FOREACH(symtable,s){
if (! strcmp(name, s->name)){
printf("ERROR -- multiple declaration of variable \"%s\"\n", name);
return 1;
}
}
printf("cannot find a symbol with the same declaration\n");
return 0;
}


int exists_Sym_loc(char const *name){
symbol *s = NULL;
printf("searching for symbol \"%s\" in table \"%s\"\n",name,currentScope->name);
if(currentScope->next == NULL){
printf("local table \"%s\" is empty\n",currentScope->name);
return 0;
}

LL_FOREACH(currentScope,s){
if (! strcmp(name, s->name)){
printf("ERROR -- multiple declaration of variable \"%s\n", name);
return 1;
}
}
printf("cannot find a symbol with the same declaration\n");
return 0;
}


struct Symbol* find_Sym(char *name){
symbol *s = NULL;
LL_FOREACH(symtable,s)
if (! strcmp(name,s->name)){
printf("\n found symbol %s",name);
return s;
}
else
return NULL;
}

void debug_printSymbolTable(){
symbol *s = NULL;

printf("\n\n\t\t - DEBUG ___ SYMBOL _ TABLE ___ DEBUG - \n\n");
printf("-----------------------------------------------------------------\n");
printf(" global \t\t| local\n");
printf("-----------------------------------------------------------------\n");

LL_FOREACH(symtable,s)
if(s->var.scope==NULL)
printf("|type:%d name:%s| \n",s->type,s->name);
else
printf("\t\t\t|type:%d name:%s| \n",s->type,s->name);

// else
// printf("|type:int value:%d name:%s scope:%s| \n ",s->var.value,s->name,s->scope->name);

}
int main(){
getch();
return 1;
}
Jul 13 '14 #1
2 2662
weaknessforcats
9,208 Expert Mod 8TB
Your compiler is telling you the line of code where the problem becomes evident. The actual error will be there or at an earlier location in the code.

What is the actual error?

The code you posted is not compilable as all the header files are absent.
Jul 13 '14 #2
donbock
2,426 Expert 2GB
Are you using C or C++?
It would be easier to refer to specific lines in your code if you used Code tags.
It is difficult to analyze your code without access to the non-Standard headers, but a few things can be said.

You should always check for malloc failure (return value is NULL).

In function pushVar ...
s->name = name; won't work in C
Shouldn't s->var.scope be set to NULL if currentScope is NULL?
I would use more brackets to make if if {} else else if {} flow less confusing.

In function pushFunc ...
s->name = name; won't work in C.

In functions exists_Sym_glob and exists_Sym_loc ...
Multiple definition error message is printed the first time a symbol match is found.

By the way, I notice you don't support nested name scopes as can be accomplished in C by defining variables inside a bracketed code block.
Jul 13 '14 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Brian Stubblefield | last post by:
Dear clc members, I am rather new to the C programming language. I have a rather large program that I am currently debugging. Currently, the following snippet of code in the c program: ...
15
by: Chris Readle | last post by:
Hi all, Somewhat new to C and I'm getting the following error from my latest code. Here's the warning I'm getting: chris_readle_project3_assignment3.c: In function `main':...
1
by: Josh Wilson | last post by:
Hey gang, So I have my stdin which is user defined file, and am wanting to write it to a temporary file (seems odd I know, but there is a sincere reason), and then use that file as the stdin for...
6
by: PraZ | last post by:
Hi all. Here is a simple code, which when compiled with gcc results in the warning "incompatible pointer type" for arg 1, as expected. But this is just what I want to do, because it makes it...
8
by: Michael | last post by:
Hi all, why do I get a message: warning: passing arg 1 of `collectInput' from incompatible pointer type In 'main' have: char inputString; collectInput(&inputString);
1
by: wanglei0214 | last post by:
I compiles a program in SLOS, but there is a warning i donot know how to remove? here is the framework of the code: typedef struct device_tree { ...... union {
13
by: william | last post by:
code segment: long int * size; char entry; ............. size=&entry; ************************************* Gcc reported 'assignment of incompatible pointer type'.
5
by: plazzasele | last post by:
I want to register a new Person by using the set and get method. I am running my code on a program ( DEVc++), and when i compile the code i get this error message: assignment from incompatible...
6
by: suvas | last post by:
I have C code. On compliation it shows error, warning: assignment from incompatible pointer type Actually I wanted to evaluate integral then sum all the integrals. I would be glad if anyone could...
1
by: Cdweller | last post by:
Below is my code snippet.I'm getting "Error:initialization from incompatible pointer type" error on line 'int *q = status;'. Obviously, I'm missing something but has no clue...:( Could someone...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.