difference between 'char *arr' and 'char arr []'

Mike Black black at beno.CSS.GOV
Wed Oct 10 07:47:17 AEST 1990


Another quote from K&R original reference (Appendix A, paragraph 7.1):
"The expression E1[E2] is identical (by definition) to *((E1)+(E2))..."
2 paragraphs later, "...array names are CONVERTED to pointers" (my
emphasis).  A seeming conflict for something that is identical.  I
got bit on this trying to port some software to MicroSoft C.  It indeed
contained struct a[] in one section and struct *a as an extern in another.
It worked on an Amiga, Sun, and Dec 3100, but not on the PC.
	Here's where K&R says it (App A, par 14.3):
"Every time an identifier of array type appears in an expression, it is
converted into a pointer...".  Ergo, an extern of type pointer will not
get converted and unless type pointer and type array are equal will cause
problems.  
Mike...

--
-------------------------------------------------------------------------------
: usenet: black at beno.CSS.GOV   :  land line: 407-494-5853  : I want a computer:
: real home: Melbourne, FL     :  home line: 407-242-8619  : that does it all!:
-------------------------------------------------------------------------------



More information about the Comp.lang.c mailing list