This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/42656] New: VLA as function parameter loses sizeof property
- From: "tbullock at comlore dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 8 Jan 2010 10:12:49 -0000
- Subject: [Bug c/42656] New: VLA as function parameter loses sizeof property
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
According to the documentation at
http://gcc.gnu.org/onlinedocs/gcc/Variable-Length.html it should be possible to
use a VLA as a function parameter and preserve the array length for use with
sizeof().
The documentation indicates that the C program at end of this description
should produce the following output
s: <This is a string>
sizeof(s): 17
s: <This is a string>
sizeof(s): 17
However gcc 4.4.1 produces the following output instead (note that the second
sizeof calculation is incorrect)
s: <This is a string>
sizeof(s): 17
s: <This is a string>
sizeof(s): 4
Note that the following C program is compiled with the -std=c99 option.
#include <string.h>
#include <stdio.h>
void
vararray(size_t l, const char s[l])
{
printf("s: <%s>\nsizeof(s): %d\n", s, sizeof(s));
}
int
main()
{
char s[] = "This is a string";
printf("s: <%s>\nsizeof(s): %d\n", s, sizeof(s));
vararray(sizeof(s), s);
return 0;
}
--
Summary: VLA as function parameter loses sizeof property
Product: gcc
Version: 4.4.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: tbullock at comlore dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42656