Forum > Suggestions

Suggestion - implement FORWARD keyword for records.

<< < (2/2)

BeniBela:

--- Quote from: PascalDragon on December 19, 2023, 10:01:46 pm ---And that is something that will not be changed. The compiler must know the size of a record to be able to embed it somewhere else (without using a Pointer) and both Pascal and FPC are designed as a single pass language (in case of FPC as far as the parser is concerned).

--- End quote ---

It does not need to change. The compiler could just support forward declarations without embedding.

And if the user tries to use the record in a field declaration, it gives an error "embedding not supported for forward types"



Such forward declarations are extremely useful. Then we could compile this:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- type //TB = record; forward; TA = record  function equals(const b: TB): boolean;end;TB = record  function equals(const a: TA): boolean;end;  

440bx:

--- Quote from: BeniBela on December 20, 2023, 12:20:07 am ---Such forward declarations are extremely useful. Then we could compile this:

--- End quote ---
I see a conceptual problem with that code.   Specifically, there should be only ONE "Equals" function that takes a TA and TB as parameters.  Not two Equals functions that take different parameters yet, from the looks of it, are supposed to do the same thing.

Navigation

[0] Message Index

[*] Previous page

Go to full version