[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]
Subject: Re: [pkcs11] Updated Proposal: All constants should have UL suffix
On 6/12/2013 5:12 PM, Stef Walter wrote:
On 12.06.2013 22:31, Michael StJohns wrote:What I started to mumble about on the web site was whether this should actually be a #define or a "static const". I don't actually have a strong opinion, and this might be too much of a change, but if we're turning these into actual ULs, then it may make sense to change these to compilable objects for type safety.Unfortunately C and C++ handle 'static const' quite differently. For eaxmple 'static const' variables cannot be used in switch statements in C. And there are notable between compilers/linkers, and versions of C. See following for an example of just one of the things that would break. Cheers,
You would think by now (20years after C 89) they would have fixed things like this.
Fair enough - comment withdrawn. Mike
Stef
example:
#include <assert.h>
#include <stdlib.h>
#define ONE 1
#define TWO 2UL
static const unsigned long THREE = 3UL;
int
main (int argc,
char *argv[])
{
assert (argc == 2);
switch (atoi(argv[1])) {
case ONE:
case TWO:
case THREE:
return 0;
default:
return 1;
}
}
$ gcc -Wall ./test.c
./test.c: In function ‘main’:
./test.c:16:2: error: case label does not reduce to an integer constant
case THREE:
[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]