Bug 71963 - Showing incompatible type when types are same.
Summary: Showing incompatible type when types are same.
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.6.2
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-07-21 19:29 UTC by Srinivas Nayak
Modified: 2016-07-22 06:31 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Srinivas Nayak 2016-07-21 19:29:48 UTC
#include <stdio.h>
int main()
{
	int k[3][3] = {{1,2,3},{4,5,6},{7,8,9}};
	int (*c)[3];
	int (*d)[3];
	c = k+1;
	d = k+2;
	*c = *d; //error: incompatible types when assigning to type 'int[3]' from type 'int *'
	k[0] = k[1]; //error: incompatible types when assigning to type 'int[3]' from type 'int *'
	printf("%d\n", (*c)[0]);
	printf("%d\n", (*d)[0]);

	return 0;
}


In the above code, errors are shown as commented.
No doubt, it is a tricky attempt to assign an array to another array.
However, aren't the types of both left hand side and right hand side same?


Sincerely,
Srinivas Nayak
Comment 1 Andrew Pinski 2016-07-22 06:01:57 UTC
Arrays decay to pointers when they are rlvalues.
Comment 2 Andreas Schwab 2016-07-22 06:31:05 UTC
C has no array assignment.