
Untitled
By: a guest on
May 27th, 2012 | syntax:
None | size: 1.26 KB | hits: 13 | expires: Never
incompatible struct types in casts/assignment?
#include <stdio.h>
int main(void)
{
int i;
int dst[] = { 10, 20, 30 }, src[] = { 1, 2, 3 };
*(struct{int _[3];}*)dst = *(struct{int _[3];}*)src;
for (i = 0; i < 3; i++) printf("%dn", dst[i]);
return 0;
}
#include <stdio.h>
#include <string.h>
int main(void)
{
int i;
int dst[] = { 10, 20, 30 }, src[] = { 1, 2, 3 };
memcpy(dst, src, 3 * sizeof(int));
for (i = 0; i < 3; i++) printf("%dn", dst[i]);
return 0;
}
#include <stdio.h>
int main(void) {
// struct T is only visible in main()
struct T {int _[3];};
int i;
int dst[] = { 10, 20, 30 }, src[] = { 1, 2, 3 };
*(struct T*)dst = *(struct T*)src;
for (i = 0; i < 3; i++) printf("%dn", dst[i]);
return 0;
}
void fails(void) {
// will cause a compilation error, because struct T is an incomplete type.
struct T t;
}
#include <stdio.h>
int main(void) {
// struct T is only visible in main()
struct T {int _[3];};
int i;
int dst[] = { 10, 20, 30 }, src[] = { 1, 2, 3 };
*(struct T*)dst = *(struct T*)src;
for (i = 0; i < 3; i++) printf("%dn", dst[i]);
return 0;
}
void fails(void) {
// will cause a compilation error, because struct T is an incomplete type.
struct T t;
}