S
Stephen Mayes
I this helloworld portable? I am vaguely aware of something called
"structure padding" and wonder if it could affect this program since the
struct only contains chars.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main (void)
{
struct
{
unsigned char var1[5];
unsigned char var2[6];
unsigned char var3[2];
} var =
{
{'H', 'e', 'l', 'l', 'o'},
{' ', 'W', 'o', 'r', 'l', 'd'},
{'!', '\n'}
};
char varcopy[sizeof(var)];
size_t i;
memcpy (varcopy, &var, sizeof(varcopy));
for (i = 0; i < sizeof(varcopy); i++)
putchar (varcopy);
return EXIT_SUCCESS;
}
"structure padding" and wonder if it could affect this program since the
struct only contains chars.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main (void)
{
struct
{
unsigned char var1[5];
unsigned char var2[6];
unsigned char var3[2];
} var =
{
{'H', 'e', 'l', 'l', 'o'},
{' ', 'W', 'o', 'r', 'l', 'd'},
{'!', '\n'}
};
char varcopy[sizeof(var)];
size_t i;
memcpy (varcopy, &var, sizeof(varcopy));
for (i = 0; i < sizeof(varcopy); i++)
putchar (varcopy);
return EXIT_SUCCESS;
}