🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #2505

sizeof() on an array argument

#2505
From: Theo Vosse
Date: Fri, 10 Nov 1995 12:42
43 lines
1709 bytes
Hi,

I've been wondering. Both the C++ compiler on my macintosh (CodeWarrior)
and GNU C++ (2.6.something) say that the size of an array passed as an
argument to a function is 4, which is the size of a pointer (or
reference).

However, both ARM and some ANSI proposal on the net (the September working
paper?) state:

* When applied to an array, the result is the total number of bytes in the
array.

The ANSI paper also explicitly adds:

* [...] array-to-pointer [...] standard conversions are suppressed on the
operand of sizeof.

What's the verdict? If I have a function

void Add(DataPoint* dp, char v[N])
{
    ... sizeof(v) ...
}

Should sizeof(v) be

a) 4
b) N
c) Another value?

I'm very interested in what the protagonists of (a) have to say...

-- 
        Theo Vosse
        ----------
        Unit for Experimental and Theoretical Psychology
        University of Leiden
        The Netherlands
---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID: <vosse-1011951040220001@fslq01.fsw.leidenuniv.nl>
Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back
Date: 10 Nov 95 12:42:32 GMT
Approved: fjh@cs.mu.oz.au
From: vosse@ruls41.fsw.LeidenUniv.nl (Theo Vosse)
Newsgroups: comp.std.c++
Subject: sizeof() on an array argument
X-Original-Date: Fri, 10 Nov 1995 10:40:22 +0100
Organization: Unit for Experimental Psychology, University of Leiden
Message-ID: <vosse-1011951040220001@fslq01.fsw.leidenuniv.nl>
X-Auth: PGPMoose V1.1 PGP comp.std.c++
 iQBFAgUBMKNIyuEDnX0m9pzZAQEyxwF/cplMCAO+UbcJetUdBlVZJTek/iXllHok
 l3LElatr8h96Qpa7FZxMFgasDLrbMi3W
 =S4Vp