Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site ucsfcgl.UUCP Path: utzoo!watmath!clyde!cbosgd!ihnp4!mhuxn!mhuxr!ulysses!ucbvax!ucsfcgl!arnold From: arnold@ucsfcgl.UUCP (Ken Arnold%CGL) Newsgroups: net.lang,net.lang.c Subject: Re: structured assembler (BASIC) [Really: C builtin functions?] Message-ID: <1883@ucsfcgl.UUCP> Date: Thu, 10-Apr-86 16:16:03 EST Article-I.D.: ucsfcgl.1883 Posted: Thu Apr 10 16:16:03 1986 Date-Received: Sat, 19-Apr-86 13:53:51 EST References: <443@3comvax.UUCP> <7900003@ztivax.UUCP> Reply-To: arnold@ucsfcgl.UUCP (Ken Arnold) Organization: UCSF Computer Graphics Lab Lines: 44 Keywords: BASIC, C Xref: watmath net.lang:2371 net.lang.c:8627 In article <202@chronon.UUCP> Eric Black writes: >Well, how about sizeof(foo)? > >It looks like a function invocation, and is known and understood >by the compiler... > >All right, all right, K & R calls it an "operator", but none of >us here are known to pick nits, are we?? :-) Not really. If "foo" is a variable, you can just as well say "sizeof foo". You only need the parentheses if "foo" is a type name, e.g., "int". I almost never use "sizeof (type)" since then I have to know which type the variable I am associating it with has. Er, let me try phrasing that in code. some_type *ptr; ptr = malloc(10 * sizeof *ptr); is better (to me) then ptr = malloc(10 * sizeof (some_type)); because it is more true. In the first case I get exactly what I want, in the second I have no guarantee that the size I'm using relates in any way to the type of "ptr". If write the first way, and then change the type of "ptr" to "some_other_type *ptr", life. Purists will note that I really should say ptr = (some_type *) malloc(10 * sizeof *ptr); But eventually malloc() will be of type "void *". This is also an argument for a new "typeof" operator. I presume, however, that ANSI has continued to ignore this, so I guess we're stuck. I'd be glad to be disabused of this notion if someone who has access to the latest draft would tell me. It sure would be nice to look at it sometime before it is officially a proposed standard. Ken Arnold P.S. Another place many people use unecessary parentheses is with "return". About 80% of the people I talk with don't even know they aren't required.