Significant chars in IDs

richw at ada-uts.UUCP richw at ada-uts.UUCP
Thu Oct 3 00:14:00 AEST 1985


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);
}

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



More information about the Comp.lang.c mailing list