473,382 Members | 1,766 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,382 software developers and data experts.

error: incompatible types in assignment

Question 1:
Expand|Select|Wrap|Line Numbers
  1.     typedef struct
  2.     { int x, y, z ;
  3.       float *wave;
  4.       float *velocity;
  5.     }Model;
  6.  
  7.     void a(Model *domain);
  8.     void b(Model *domain, int t);
  9.  
  10.  
  11.     int main()
  12.     {int i;
  13.      int j=10;
  14.  
  15.      Model Domain;
  16.      Domain=(Model *)malloc(sizeof(Model);  
  17.  
  18.      for (i=0; i<10; i++)
  19.         a(domain);
  20.  
  21.      return;
  22.     }
  23.  
if I block "Domain=(Model *)malloc(sizeof(Model)", the compiler doesnt show any error,
but if this line is visible or avaliable, the error will come out:

error: incompatible types in assignment;

If anyone can give me the direction of this problem, highly appreciated ~



Question 2:
Expand|Select|Wrap|Line Numbers
  1.       typedef struct
  2.     { int x, y, z ;
  3.       float *wave;
  4.       float *velocity;
  5.     }Model;
  6.  
I define a struct (Model) in struct.h file, which can be called by any other functions. Another header file is called "functions.h" which includes
all functions I have, such as a(Model *domain, int t), b(int d, int f, int g) .

When I compile my whole codes, the compile shows some errors:

error: syntax error before "*" token. This error points to a(Model *domain, int t). why does it show here? I declare struct in .h file and every subfunctions (a(), b()) also include it.
I am confused about this problem.
Jun 24 '08 #1
6 1709
gpraghuram
1,275 Expert 1GB
Answer for question 1...
You are trying to allocate memory for a stack object.
Malloc shou;ld be used only for pointers

Raghu
Jun 24 '08 #2
JosAH
11,448 Expert 8TB
Question 1:
Expand|Select|Wrap|Line Numbers
  1. Model Domain;
  2. Domain=(Model *)malloc(sizeof(Model);  
  3.  
Your Domain variable has type Model. You cast the pointer returned by malloc
to a pointer to a Model. A pointer to a Model isn't a Model. Make your Domain
variable a pointer to a Model instead:

Expand|Select|Wrap|Line Numbers
  1. Model* Domain;
  2. Domain=(Model *)malloc(sizeof(Model);  
  3.  
kind regards,

Jos
Jun 24 '08 #3
Or... don't do a malloc at all for the domain variable, eg:

Expand|Select|Wrap|Line Numbers
  1. Modeldim domain;
And that's all. I have the feeling you're trying to run before walking. Maybe you should first try your program without mallocs (do you really need them?).
Jun 24 '08 #4
No clue regarding your second question. Maybe you could paste in some code.
Jun 24 '08 #5
weaknessforcats
9,208 Expert Mod 8TB
I define a struct (Model) in struct.h file, which can be called by any other functions. Another header file is called "functions.h" which includes
all functions I have, such as a(Model *domain, int t), b(int d, int f, int g) .

When I compile my whole codes, the compile shows some errors:
Does functions.h include struct.h ?
Does the code include struct.h before including functions.h?

If the answer to both these questions is NO, then you have your answer.
Jun 25 '08 #6
Does functions.h include struct.h ?
Does the code include struct.h before including functions.h?

If the answer to both these questions is NO, then you have your answer.
I modified my codes like you said, it works now. Thank you very much.
Jun 25 '08 #7

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

Similar topics

7
by: Brian Stubblefield | last post by:
Dear clc members, I am new to C and am posting several messages concerning a large C program that I am debugging. I am encountering a "incompatible types in assignment" warning for the...
2
by: Dennis Schulz | last post by:
Hi all, the following programm is supposed to check for login and password with inbuilt linux functions. in line 57 and 64 there are erorrs: incompatible types in asignment. whats wrong with...
8
by: fei.liu | last post by:
I have the following source code. It seems wierd to me why gca's value cannot be reassigned. It's afterall a pointer and has a pointer value. I am aware that the standard says it's not allowed. But...
4
by: John Doe | last post by:
segmentation error !!!! hi guys , i wrote this program to multiply two matrices (just the basic code without checkin 4 the condition n==p ) " #include<stdio.h> main() { int a,b,c; int...
13
by: william | last post by:
code segment: long int * size; char entry; ............. size=&entry; ************************************* Gcc reported 'assignment of incompatible pointer type'.
4
by: lovecreatesbea... | last post by:
Gcc only gives out a warning: `assignment discards qualifiers from pointer target type' against code such as following: $ type a.c int main(void) { const char *pc; char *p = pc;
10
by: MisterE | last post by:
typedef struct sg { int a; } G; int c(G* g) { return g->a; }
6
by: billiabon | last post by:
Hello,everybody! I need your help! My problem is this assignment char pnm; void enqueue(int pd,char pnm,int pnum,int ptm,struct queue *z) {struct node *p; p=(struct node...
5
by: happytoday | last post by:
I compiled that program under turbo C without any problems but with sunstudi I found those errors: "pnt02ma1.c", line 37: warning: implicit function declaration: system "pnt02ma1.c", line 58:...
2
by: akhilesh.noida | last post by:
I am trying to compile glibc-2.5 for ARM based board. But I am getting errors while configuring it. Please check and give your inputs for resolving this. configure command : $...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.