|
You are correct that I need a '*' before rc2.
The program should not compile. Since ptrv2 is pointing to void, ptrv2++ makes so sense. The compile does not know how much to alter ptrv2 by. That is the purpose of the little test program. __STDC_WANT_DEC_FP__ should have no effect here (there is no Decimal floating-point).
But, just in case pcc supports it, and my test had it, I included it. the C99 spec seems pretty quiet on this point, but gcc does also assign void and function
types a sizeof 1 for convenience with pointer calculations, and only generates a warning if -Wpointer-arith is given (this is not included by -Wall) pcc accepts -Wpointer-arith but doesn't generate any warnings at this time perhaps the SIGFPE was caused by a divide by zero relating to this? "ptrv2++" violates a constraint of 6.5.6 additive operators (it is
NOT a pointer to a complete object type). 6.2.5 Types 19 The void type comprises an empty set of values; it is an incomplete object type that cannot be completed. 6.3.2.1 Lvalues, arrays, and function designators 1 An lvalue is an expression (with an object type other than void) that potentially designates an object;64) if an lvalue does not designate an object when it is evaluated, the behavior is undefined. When an object is said to have a particular type, the type is specified by the lvalue used to designate the object. A modifiable lvalue is an lvalue that does not have array type, does not have an incomplete type, does not have a const-qualified type, and if it is a structure or union, does not have any member (including, recursively, any member or element of all contained aggregates or unions) with a const-qualified type. 64) The name "lvalue" comes originally from the assignment expression E1 = E2, in which the left operand E1 is required to be a (modifiable) lvalue. It is perhaps better considered as representing an object "locator value". What is sometimes called "rvalue" is in this International Standard described as the "value of an expression". An obvious example of an lvalue is an identifier of an object. As a further example, if E is a unary expression that is a pointer to an object, *E is an lvalue that designates the object to which E points. 6.5.2.4 Postfix increment and decrement operators Semantics 2 ... See the discussions of additive operators and compound assignment for information on constraints, types, and conversions and the effects of operations on pointers. ... 6.5.6 Additive operators Constraints 2 For addition, either both operands shall have arithmetic type, or one operand shall be a pointer to a complete object type and the other shall have integer type. (Incrementing is equivalent to adding 1.) It do not crash anymore AFAICT.
But pcc allows arithmetic on void pointers since a few years ago, I had to add it since there were too much problems by not allowing it since gcc do not complain about it. Sometime it may be reasonable to disallow it again, but not yet. |
This fails compilation (with errors) on my NetBSD/i386 system.. adding that
and the program compiles and runs with exit value 1
Then, I don't see the relevance of __STDC_WANT_DEC_FP__ since that string
does not appear anywhere in the pcc sources.. Is an include file from your
environment being brought in somehow?