This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Why convert to pointer type before added to a pointer


Hi Jeff,


It's an unfortunate aspect of the type system we have -- basically both operands of a binary operator need to have compatible types.


Why does our type system behave like this? Could you or somebody else give me an outline of the type system?



The first approach is to have a separate set of operators such as
PLUS_PTR_EXPR, MINUS_PTR_EXPR which do not require their operands
to be the same type. That's ugly simply because everywhere you generate or test for PLUS_EXPR or MINUS_EXPR you have to to examine
the types to determine instead you should be using PLUS_PTR_EXPR
or MINUS_PTR_EXPR.


The other approach is to relax the type system.  That's bad from the
standpoint of being able to perform internal consistency checking.

I think the latter one is better. I would even say it's to correct the type system. In the C99 standard, it reads

  6.5.6.2
  For addition, either both operands shall have arithmetic type,
  or one operand shall be a pointer to an object type and the
  other shall have integer type.

Adding two pointers is not allowed by the constraints. But I may miss something, since I now have little knowledge on our type system.


cheers -- Jie


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]