Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2006-09

strange code in TThread in classesh.inc

4 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Graeme Geldenhuys

What is the point of these ifdef's, they are identical in the sense of variable names and types...?

----------Line 1208 in classesh.inc ------------------------
<snip>
    property Terminated: Boolean read FTerminated;
{$ifdef Unix}
  private
    // see tthread.inc, ThreadFunc and TThread.Resume
    FSem: Pointer;
    FInitialSuspended: boolean;
    FSuspendedExternal: boolean;
  {$ifdef linux}
    FPid: LongInt;
  {$endif}
{$endif}
{$ifdef netwlibc}
  private
    // see tthread.inc, ThreadFunc and TThread.Resume
    FSem: Pointer;
    FInitialSuspended: boolean;
    FSuspendedExternal: boolean;
    FPid: LongInt;
{$endif}
  public
<snip>
----------------------------------

Regards,
- Graeme -

Reply by email

Tomas Hajny
to Graeme Geldenhuys
Graeme Geldenhuys wrote 26 lines
What is the point of these ifdef's, they are identical in the sense of variable names and types...? ----------Line 1208 in classesh.inc ------------------------ <snip> property Terminated: Boolean read FTerminated; {$ifdef Unix} private // see tthread.inc, ThreadFunc and TThread.Resume FSem: Pointer; FInitialSuspended: boolean; FSuspendedExternal: boolean; {$ifdef linux} FPid: LongInt; {$endif} {$endif} {$ifdef netwlibc} private // see tthread.inc, ThreadFunc and TThread.Resume FSem: Pointer; FInitialSuspended: boolean; FSuspendedExternal: boolean; FPid: LongInt; {$endif} public <snip> ----------------------------------

What would be your suggestion - change it to {$IF defined(UNIX) or defined(NETWLIBC)}? I'd say that it would be better to make the interface completely common, i.e. to get rid of these IFDEFs completely (e.g. by including a record defined in platform specific part of the unit).

Tomas

Reply by email

Graeme Geldenhuys
to Tomas Hajny
Tomas Hajny wrote 6 lines
What would be your suggestion - change it to {$IF defined(UNIX) or defined(NETWLIBC)}? I'd say that it would be better to make the interface completely common, i.e. to get rid of these IFDEFs completely (e.g. by including a record defined in platform specific part of the unit). Tomas

Yeah, I just thought it is unnecessary code duplication and extra work if it has to be maintained. The record idea sounds like a good plan and will get rid of the IFDEF's completely. Sound make the code much easier to read as well.

Regards,
- Graeme -

Reply by email

Vincent Snijders
to Graeme Geldenhuys
Graeme Geldenhuys wrote 12 lines
On 29/09/06, Tomas Hajny wrote: > What would be your suggestion - change it to {$IF defined(UNIX) or > defined(NETWLIBC)}? I'd say that it would be better to make the interface > completely common, i.e. to get rid of these IFDEFs completely (e.g. by > including a record defined in platform specific part of the unit). > > Tomas Yeah, I just thought it is unnecessary code duplication and extra work if it has to be maintained. The record idea sounds like a good plan and will get rid of the IFDEF's completely. Sound make the code much easier to read as well.

I won't argue the maintenance aspect, but I doubt your case for readability.

If you make this change, these fields are not in the same file as the class definition anymore, so I would have to look at two places. And the implementation becomes more unreadible.

Instead of
   FSem := 0;
It will be (assuming a record field name FPrivateData)
   FPrivateData.Sem := 0;

Vincent

Reply by email