Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.compilers.lcc > #957

lcc-win bug, 2-dimensional VLA

Path csiph.com!weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From Keith Thompson <Keith.S.Thompson+u@gmail.com>
Newsgroups comp.compilers.lcc
Subject lcc-win bug, 2-dimensional VLA
Date Mon, 08 Jan 2024 11:27:48 -0800
Organization None to speak of
Lines 50
Message-ID <87jzojpqvf.fsf@nosuchdomain.example.com> (permalink)
MIME-Version 1.0
Content-Type text/plain
Injection-Info dont-email.me; posting-host="f909ce6842d964f6deb0fc108ae5e13b"; logging-data="1742268"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/CUXQ+6f5NMKt8Cv/9h+nE"
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock sha1:Y4NKhrEbMu3rXD3uhTd8VDQ7EoU= sha1:C5LS5rLertvV3Fw3SevwUGMR6mc=
Xref csiph.com comp.compilers.lcc:957

Show key headers only | 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