Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

lcc-win bug, 2-dimensional VLA

58 views
Skip to first unread message

Keith Thompson

unread,
Jan 8, 2024, 2:27:50 PMJan 8
to
A recent discussion in comp.lang.c has turned up what I believe is a bug
in lcc-win.

Consider the following program:

#include <stdio.h>
int main(void) {
int row_count = 10;
int col_count = 20;
int vla_2d[row_count][col_count];
printf("sizeof vla_2d[0][0] = %zu\n", sizeof vla_2d[0][0]);
printf("sizeof vla_2d[0] = %zu\n", sizeof vla_2d[0]);
printf("sizeof vla_2d = %zu\n", sizeof vla_2d);
printf("rows : %zu\n",
sizeof vla_2d / sizeof vla_2d[0]);
printf("elements per row : %zu\n",
sizeof vla_2d[0] / sizeof vla_2d[0][0]);
printf("Total elements : %zu\n",
sizeof vla_2d / sizeof vla_2d[0][0]);
}

The correct output, assuming int is 4 bytes, is:

sizeof vla_2d[0][0] = 4
sizeof vla_2d[0] = 80
sizeof vla_2d = 800
rows : 10
elements per row : 20
Total elements : 200

The last three lines should be the same regardless of sizeof (int).

gcc, clang, and tcc all give this output, but lccwin gives:

sizeof vla_2d[0][0] = 4
sizeof vla_2d[0] = 16
sizeof vla_2d = 3200
rows : 200
elements per row : 4
Total elements : 800

I'm not aware of any real-world code that's affected by this, so
consider that when setting a priority.

(I don't know whether jacob navia still follows this newsgroup.)

--
Keith Thompson (The_Other_Keith) Keith.S.T...@gmail.com
Working, but not speaking, for Medtronic
void Void(void) { Void(); } /* The recursive call of the void */
0 new messages