Groups | Search | Server Info | Login | Register


Groups > comp.compilers.lcc > #957

lcc-win bug, 2-dimensional VLA

From Keith Thompson <Keith.S.Thompson+u@gmail.com>
Newsgroups comp.compilers.lcc
Subject lcc-win bug, 2-dimensional VLA
Date 2024-01-08 11:27 -0800
Organization None to speak of
Message-ID <87jzojpqvf.fsf@nosuchdomain.example.com> (permalink)

Show all headers | View raw


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.Thompson+u@gmail.com
Working, but not speaking, for Medtronic
void Void(void) { Void(); } /* The recursive call of the void */

Back to comp.compilers.lcc | Previous | Next | Find similar


Thread

lcc-win bug, 2-dimensional VLA Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-01-08 11:27 -0800

csiph-web