Bug 71963

Summary: Showing incompatible type when types are same.
Product: gcc Reporter: Srinivas Nayak <sinu.nayak2001>
Component: cAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED INVALID    
Severity: normal    
Priority: P3    
Version: 4.6.2   
Target Milestone: ---   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed:

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.