mod.std.c Digest V6#6

Orlando Sotomayor-Diaz osd at hou2d.UUCP
Fri May 10 12:20:42 AEST 1985


From: Orlando Sotomayor-Diaz (The Moderator) <cbosgd!std-c>


mod.std.c Digest            Thu,  9 May 85       Volume 6 : Issue   6 

Today's Topics:
            mod.std.c V6#4 rebuttal to: Function pointers
                        Pointer math and ints
----------------------------------------------------------------------

Date: Wed May  8 20:13:25 1985
From: nbires!gangue!obo586!dir
Subject: mod.std.c V6#4 rebuttal to: Function pointers
To: gangue!nbires!cbosgd!std-c

>	When an expression that has integral type is added to or
>	subtracted from a pointer, the integral value is converted
>	to an address offset by multiplying it by the size of the
>	object pointed to.
>
>Since the size of a function object is not defined, I believe this
>should be amended to disallow expressions which combine integers and
>pointers to functions:
>
>	foo + 1			/* illegal */

No! No! No!  What about the following (which is legal and works):

	int (*afp[])();

This is an array of pointers to functions.  All arrays in C can be
used as xxx[n] or *(xxx+n); more explicitly, an array name is actually
the address of the first element of the array and is a constant (which
is why an array name cannot be an lvalue).  Put this all together and
you get that arithmetic on a pointer-to-function is a necessary thing.


Dan Rosenblatt
obo Systems, Inc.
...{ihnp4!denelcor,nbires!gangue}!obo586!dir

------------------------------

Date: 9 May 85 14:21:39 CDT (Thu)
From: plus5!hokey (Hokey)
Subject: Pointer math and ints
To: std-c at cbosgd

I understand that the proposed C Standard does not require pointers to
be the same size as ints.  I can handle this with no problems.

What about pointer math?  Is this still guaranteed to fit into an int?
If not, *much* software will break, and the offending code will be hard
to find:

	(from K & R, 5.4 Address Arithmetic, p98.  Indentation and {}, mine.)

	int strlen(s)
	  char *s; {
	    char *p = s;

	    while (*p != '\0')
		p++;
	    return(p-s);
	}

This particular problem is *rampant* on most Macintosh C compilers.

What does the Committee have to say about this issue?

[ "When two pointers to members of the same array object are substracted,
   the result is converted (by division by the size of the member) to
   a signed integer (the size of which is implementation defined)
   representing the difference of the subscripts of the two array
   members.  As with any other arithmetic overflow, if the result does
   not fit in the space provided, the behavior is undefined. If two
   pointers that do not point to members of the same array object are
   substracted, this conversion is undefined, because such pointers do
   not necessarily differ by an integral multiple of the size of the
   object."

   From C.3.6 Additive Operators (semantics), p. 21, draft 85-008.

		-- Mod -- ]

------------------------------

End of mod.std.c Digest - Thu,  9 May 85 22:12:59 EDT
******************************
USENET -> posting only through cbosgd!std-c.
ARPA -> ... through cbosgd!std-c at BERKELEY.ARPA (NOT to INFO-C)
In all cases, you may also reply to the author(s) above.



More information about the Mod.std.c mailing list