public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/42656]  New: VLA as function parameter loses sizeof property
@ 2010-01-08 10:13 tbullock at comlore dot com
  2010-01-08 10:21 ` [Bug c/42656] " pinskia at gcc dot gnu dot org
  0 siblings, 1 reply; 2+ messages in thread
From: tbullock at comlore dot com @ 2010-01-08 10:13 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug c/42656] VLA as function parameter loses sizeof property
  2010-01-08 10:13 [Bug c/42656] New: VLA as function parameter loses sizeof property tbullock at comlore dot com
@ 2010-01-08 10:21 ` pinskia at gcc dot gnu dot org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2010-01-08 10:21 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2010-01-08 10:20 -------
No, the manual is just a little hard to read really.  The point about sizeof is
not connected with arguments at all but the normal VLA interface.  Also the VLA
decays to a pointer in this case as required by the normal argument C90/C99
decaying rules.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42656


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-01-08 10:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-01-08 10:13 [Bug c/42656] New: VLA as function parameter loses sizeof property tbullock at comlore dot com
2010-01-08 10:21 ` [Bug c/42656] " pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).