Forum > Beginners

[Solved] Is it possible to const an argument passed by reference in FPC?

<< < (12/13) > >>

PascalDragon:

--- Quote from: 440bx on August 01, 2019, 11:19:23 am ---That's one of the reasons the definition of WriteFile is _incorrect_.  Another reason is, there are no untyped parameters in C.  Using untyped parameters is not semantically equivalent to "void*".

It's really amazing the extent some FPC developers, you among them, go to pretend an incorrect definitions or compiler behavior is "correct".  Very unfortunate.

--- End quote ---
The declarations are definitely correct (in the sense that they can be used for the same functionality as the C declaration), what they aren't is equivalent to the MSDN documentation.

What I do grant you however is that we don't have the equivalent declaration as an overload. Those should in my opinion definitely be there as those declarations with untyped parameters or typed var parameters are considered "convenience" declarations and thus an "add on".

ikel:
Hi everyone,

Thanks for replies and for code examples... :D
I thought I got the best practices of using const is passing a reference (like c++'s string  *input). I was wrong, it is more complicated than what I had expected. Up to discussion on COM, const and stdcall, I pretty much got it.

Then discussion went into untyped... I got lost... :o
I will re-read again, making sure I got it, along with code examples, then I will write up a summary.

440bx:

--- Quote from: ikel on August 02, 2019, 11:55:25 pm ---Then discussion went into untyped... I got lost... :o

--- End quote ---
I suggest _never_ using untyped parameters. 

An untyped parameter implicitly causes the caller to pass any data type by reference since the parameter has no type.  It's one of those "great ideas" from a compiler writer who inhaled too much leaded red paint fumes before reaching the keyboard.

Thaddy:
Tell that to C api writers too, please  :D But I mostly agree.
Btw I helped introduced OpaquePointer and a TOpaqueData - empty - record to avoid untyped. It is in 3.2.0. The ratio I had was for passing C structures around w/o changing them from Pascal code, although it is also used in the rtl and rtl-generics.

Some of the untyped stuff can be resolved with the above. It is in systemh.inc. Not Delphi compatible, though.

PascalDragon:

--- Quote from: 440bx on August 03, 2019, 12:27:00 am ---
--- Quote from: ikel on August 02, 2019, 11:55:25 pm ---Then discussion went into untyped... I got lost... :o

--- End quote ---
I suggest _never_ using untyped parameters. 

An untyped parameter implicitly causes the caller to pass any data type by reference since the parameter has no type.  It's one of those "great ideas" from a compiler writer who inhaled too much leaded red paint fumes before reaching the keyboard.

--- End quote ---
*rolls eyes*

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version