🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #4030

Re: Binary includes

#4030
From: Joerg Czeranski
Date: Tue, 19 Sep 1995 00:52
31 lines
1584 bytes
j@the_one.epita.fr (Jedi/Sector One) wrote:
] [...]
]
]   Another problemes with the actual ANSI C revision is that there is no way of
] knowing how many items an array contains without an end mark. Just look at the
] first example I gave : how is it possible to know that there are 4 items at
] run-time ? The only way to do it would be to add an item like "0xff" at the
] end of that array, and then to test each time an item is processed, whether it
] is the end-mark constant or a classical value.
] 
]   Maybe the next C standard should solve this with something like
] 
]     int nbItems;
]     static char table[nbItems] = { 0x25, 0x3f, 0x7f, 0x32 };
] 
]   nbItems has not to be const, even in C++, as we expect it to be modified to
] the number of items following this initialized array.
] 
]   Greetings, Frank.

This problem is easily solved in the following way:

static char table[] = { 0x25, 0x3f, 0x7f, 0x32 };
int nbItems = sizeof table / sizeof *table;

joerg

--
Joerg Czeranski                 EMail czeranski@informatik.tu-clausthal.de
Osteroeder Strasse 55                 czeranski@rz.tu-clausthal.de
D 38678 Clausthal-Zellerfeld    WWW   http://www.in.tu-clausthal.de/~injc/
Technical Details
Message-ID: <43l48s$ffg@ikarus.rz.tu-clausthal.de>
Path: arc1-ca.pugleaf.net!trillian.in.tu-clausthal.de!injc

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!trillian.in.tu-clausthal.de!injc
From: joerg.czeranski@informatik.tu-clausthal.de (Joerg Czeranski)
Newsgroups: comp.std.c
Subject: Re: Binary includes
Date: 19 Sep 1995 00:52:44 GMT
Organization: TU Clausthal, IfI
Message-ID: <43l48s$ffg@ikarus.rz.tu-clausthal.de>
NNTP-Posting-Host: trillian.in.tu-clausthal.de
X-Newsreader: NNLINK 0.2