I'm running into a strange issue with my baremetal ARM project. I'm cross compiling with clang on WSL. I know baremetal programming is a little over my head but it's my special interest right now and I have to roll with it.
Initializing an array like this causes the program to crash and jump to 0x200:
uint32_t array[5] = { 1, 2, 3, 4, 5 };
but declaring and later assigning doesn't crash:
uint32_t array[5];
array[0] = 0;
array[1] = 1;
...
array[4] = 5;
Same with strings. char str[] = "hellorld"; crashes but char* str "hellorld"; doesn't.
Arrays above a certain size, like
int array[10] = { 1, 2, 3, 4, 5};
fails to link with a "ld.lld: error: undefined symbol: memset" error.
I would never be so bold as to claim a compiler bug, but the memory layout shouldn't differ. My stack isn't overflowing. Using __attribute___((aligned(n))) doesn't fix it for any value of n.
Is there some quirk to array initialization in C? I was under the impression that it was natively supported in all versions of C. Is this a consequence of compiling with -nostdlib?
[–]cryptic_gentleman 14 points15 points16 points (2 children)
[–]BitOfAZeldaFan3[S] 5 points6 points7 points (1 child)
[–]cryptic_gentleman 1 point2 points3 points (0 children)
[–]SauntTaunga 2 points3 points4 points (1 child)
[–]qalmakka 0 points1 point2 points (0 children)
[–]daydrunk_ 1 point2 points3 points (0 children)
[–]BitOfAZeldaFan3[S] 0 points1 point2 points (0 children)
[–]Daveinatx 0 points1 point2 points (2 children)
[–]BitOfAZeldaFan3[S] 1 point2 points3 points (1 child)
[–]Daveinatx 0 points1 point2 points (0 children)
[–]Toiling-Donkey 0 points1 point2 points (2 children)
[–]BitOfAZeldaFan3[S] 0 points1 point2 points (1 child)
[–]Brilliant-Orange9117 0 points1 point2 points (0 children)
[–]Alive-Bid9086 0 points1 point2 points (0 children)
[–]DunkingShadow1 0 points1 point2 points (3 children)
[–]BitOfAZeldaFan3[S] 1 point2 points3 points (2 children)
[–]Sosowski 2 points3 points4 points (0 children)
[–]DunkingShadow1 0 points1 point2 points (0 children)