[fpc-devel] Typed addresses, revisited

Florian Klaempfl florian at freepascal.org
Sun Oct 8 11:39:11 CEST 2006


Jonas Maebe schrieb:
> 
> On 07 Oct 2006, at 21:42, Micha Nelissen wrote:
> 
>> I propose to enable it for 2.3/2.9, i.e. after 2.2, because, as Jonas
>> said, it breaks semantics for arithmetic on non-typecasted pointers that
>> point to something that is not size 1.
> 
> How will this change after 2.2?
> 
>> To that end, the compiler will now warn you of possible {$T+}-breaking
>> code: when you do arithmetic on an untyped pointer. Tests tbf/tb0182,
>> tbf/tb0183, and tbs/tb0504 test the proper working of this warning.
> 
> I don't like this. There is nothing wrong with pointer arithmetic on 
> untyped pointers. At most it should be a hint, although even that is 
> doubtful in my eyes since there really is no error. It's a bit similar 
> to giving hints/warning for discarding function results in {$x+} mode, 
> because doesn't work in {$x-} mode (but worse, since pointer arithmetic 
> on untyped pointers in {$t-} mode is by no means always wrong in {$t+} 
> mode and it forces people to add useless typecasts whenever they declare 
> a plain variable as pointer and perform calculations on it).

I think the construct
@var+1
is dangerous because
- its pointer magic (always not good ;))
- its behaviour depends on T+/-

Making it pointer(@var)+1 clarifies things.



More information about the fpc-devel mailing list