We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,111 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

error: incompatible types in assignment

Question 1:

typedef struct
	{ int x, y, z ;
	  float *wave;
	  float *velocity;
	}Model;

	void a(Model *domain);
	void b(Model *domain, int t);


	int main()
	{int i;
	 int j=10;

	 Model Domain;
	 Domain=(Model *)malloc(sizeof(Model);  

	 for (i=0; i<10; i++)
	    a(domain);

	 return;
	}

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 appreciate~


Question 2:

typedef struct
	{ int x, y, z ;
	  float *wave;
	  float *velocity;
	}Model;

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.

4
Contributors
5
Replies
2 Days
Discussion Span
4 Years Ago
Last Updated
6
Views
fishwater00
Newbie Poster
18 posts since Jun 2008
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

malloc allocates memory and returns a pointer to the beginning of that block of memory. You need to assign it to some pointer not an object as you are doing here. Change that to pointer and it should work.

i couldnt really understand your 2nd qs, would be helpful if you attached the files also.

Agni
Practically a Master Poster
674 posts since Dec 2007
Reputation Points: 431
Solved Threads: 119
Skill Endorsements: 4

yes Agni is right. U should define Domain as pointer and not Object:

Model *Domain;
Luckychap
Posting Pro in Training
445 posts since Aug 2006
Reputation Points: 83
Solved Threads: 61
Skill Endorsements: 0

And please check for succesful allocation and if yes then dont fgt to free this block of memory once you'r done

Agni
Practically a Master Poster
674 posts since Dec 2007
Reputation Points: 431
Solved Threads: 119
Skill Endorsements: 4
a(domain);

should be

a(Domain);

And main should return 0 on successful return. Perhaps it internally does so. But its good practice to specify them explicitly.

ssharish

ssharish2005
Posting Whiz in Training
253 posts since Dec 2006
Reputation Points: 73
Solved Threads: 20
Skill Endorsements: 0

Thank you very much. I got it

fishwater00
Newbie Poster
18 posts since Jun 2008
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0767 seconds using 2.65MB