[net.lang.c] Significant chars in IDs

richw@ada-uts.UUCP (10/02/85)

I have a simple (?) question.  How many characters are significant
for the following types of identifiers?  I've included what
Kernighan/Ritchie says for each case, but have my doubts for
some (those which refer to counter-examples at the end of this
note).  Is it simply the case that I've got a lenient C compiler?
Can anybody quote the "standard" for these cases?

Thanks in advance,

Rich Wagner
-------------------------------------------------------------------------

External data (e.g. "int foo;" declared outside all functions) :
      (machine dependent according to K&R; agreed)

External functions (e.g. doit()  { ... }) :
      (machine dependent according to K&R; agreed)

Data local to a file (e.g. "static int foo" declared outside functions) :
      (8 according to K&R, but see TEST1, which prints { 1, 2 })

Data local to a function (e.g. "int foo" declared inside a function) :
      (8 according to K&R, but see TEST2, which prints { 1, 2 })

Struct field names :
      (??? according to K&R; see TEST3, which prints { 1, 2 })

/*------------------------TEST1-----------------------*/

static int long_name_suf_1;
static int long_name_suf_2;

main()
{
    long_name_suf_1 = 1;
    long_name_suf_2 = 2;
    printf("{ %d, %d }\n", long_name_suf_1, long_name_suf_2);
}

/*------------------------TEST2-----------------------*/

main()
{
    int long_name_suf_1;
    int long_name_suf_2;
    
    long_name_suf_1 = 1;
    long_name_suf_2 = 2;
    printf("{ %d, %d }\n", long_name_suf_1, long_name_suf_2);
}

/*------------------------TEST3-----------------------*/

typedef struct {
    int long_name_suf_1;
    int long_name_suf_2;
} pair; 

main()
{
    pair obj;
    
    obj.long_name_suf_1 = 1;
    obj.long_name_suf_2 = 2;
    printf("{ %d, %d }\n",
           obj.long_name_suf_1,
           obj.long_name_suf_2);
}

/*----------------------------------------------------*/

gwyn@BRL.ARPA (VLD/VMB) (10/06/85)

C is supposed to support AT LEAST 8 significant characters in
"internal" names and AT LEAST 6, possibly monocase, significant
characters in "external" names.  On the PDP-11, internal names
sometimes are restricted to 7 characters instead of 8 (this is
a bug).

X3J11 specifies AT LEAST 31 signifcant characters in internal
identifiers and macro names and the same restrictions as above
on external identifiers.

There are compilers supporting longer significance in identifiers,
but for portability you must not rely on more than the minimum.