Character constants

Terry Franklin Byrum byrum at cs.odu.edu
Wed Mar 8 01:47:28 AEST 1989




I am borrowing this account; see signature below.

Speaking of checking sizeof() to determine language specifications, I've
found it to be of even greater use in revealing compiler aberrations (BUGS!!).

Try the following little program on your "favorite" compiler.  Explaining each
line is a good exercise for the novice, and loooking at the output is a good
test of a compiler.  Notice that the Microsoft compiler gets line 2 correct,
but blows line 3: incredible since it is a fundamental rule of C language
that p[i] == *(p + i) for any pointer p and int i.  With attitudes like that,
it's a wonder it ever gets any array indexing or pointer indirection right!

                                        Lloyd Kremer
                                        Brooks Financial Systems
                                        ...!xanth!brooks!lloyd
                                        Have terminal ... will hack!

------------------cut here------------------------------------------
main()
{
	double foo[2][10];

	printf("sizeof(foo) == %d\n", sizeof(foo));
	printf("sizeof(foo[0]) == %d\n", sizeof(foo[0]));
	printf("sizeof(*foo) == %d\n", sizeof(*foo));
	printf("sizeof(foo[0][0]) == %d\n", sizeof(foo[0][0]));
	printf("sizeof(**foo) == %d\n", sizeof(**foo));
	printf("sizeof(*foo[0]) == %d\n", sizeof(*foo[0]));
	printf("sizeof((*foo)[0]) == %d\n", sizeof((*foo)[0]));
	return(0);
}

/* CORRECT OUTPUT: (assuming sizeof(double) == 8)
sizeof(foo) == 160
sizeof(foo[0]) == 80
sizeof(*foo) == 80       Microsoft 5.1 C Compiler says 160 here!  (BROKEN!!)
sizeof(foo[0][0]) == 8
sizeof(**foo) == 8
sizeof(*foo[0]) == 8
sizeof((*foo)[0]) == 8
*/
------------------cut here------------------------------------------

-- 

	Inventions have long since reached their limit --
	and I see no hope for further developments.
		- Julius Frontinus, world famous engineer, Rome, 10 AD

                                |  Terry Franklin (Frank) Byrum
                                |  BROOKS Financial Systems, Inc.
   ___                          |  INET:  byrum at cs.odu.edu
  /__  _.  __. _ _  /_          |  UUCP:  ...!sun!xanth!brooks!byrum 
 /   _/ \_(_/|_|\|_/ \          |  DISCLAIMER: No one listens anyway! 



More information about the Comp.lang.c mailing list