Re: [pkcs11] Updated Proposal: All constants should have UL suffix

From
Stef Walter <>
Date
2013-06-12T21:12:48+00:00
ID
Thread
Re: [pkcs11] Updated Proposal: All constants should have UL suffix
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,

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: