On Sun, 2 Aug 2020, Kamil Rytarowski wrote:
On 02.08.2020 15:57, Taylor R Campbell wrote:But it sounds like the original motivation is that it triggered -Wvla...which frankly strikes me as a compiler bug since there's obviously no actual VLA created in sizeof; as far as I can tell there's no semantic difference between sizeof(device_t[n]) and sizeof(device_t) * n.This is not true: #include <stdio.h> int main(int argc, char **argv) { printf("sizeof = %zu\n", sizeof(int[argc])); return 0; } $ ./a.out sizeof = 4 $ ./a.out 12 3 sizeof = 12 $ ./a.out 12 3 45 6 sizeof = 20
Modifying your example slightly, I print both variations:
#include <stdio.h>
int
main(int argc, char **argv)
{
printf("sizeof = %zu\t%zu\n", sizeof(int[argc]), sizeof(int) * argc);
return 0;
}
speedy:paul {653} ./a.out
sizeof = 4 4
speedy:paul {654} ./a.out 12 3
sizeof = 12 12
speedy:paul {655} ./a.out 12 3 45 6
sizeof = 20 20
Looks the same to me!
+--------------------+--------------------------+-----------------------+
| Paul Goyette | PGP Key fingerprint: | E-mail addresses: |
| (Retired) | FA29 0E3B 35AF E8AE 6651 | paul%whooppee.com@localhost |
| Software Developer | 0786 F758 55DE 53BA 7731 | pgoyette%netbsd.org@localhost |
+--------------------+--------------------------+-----------------------+