Forum > FPC development

Imported C Structure is not mapped correctly

<< < (2/2)

domibay_hugo:

--- Quote from: PascalDragon on January 05, 2021, 09:04:14 am ---
--- Quote from: domibay_hugo on January 04, 2021, 04:48:11 pm ---Although I had the understanding that the packed record definition is required to match with C Language Library Definitions.
--- End quote ---

No. packed ensures that there is no padding between fields of a record. That is not the case by default in C.


--- Quote from: domibay_hugo on January 04, 2021, 04:48:11 pm ---I also found that the unit ctypes includes the .inc file /rtl/linux/ptypes.inc
which again defines the directives:

--- 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";}};} ---{$I ctypes.inc}{$packrecords c} 
--- End quote ---

That only applies to the records declared inside the ctypes unit (and only if they aren't declared as packed).

--- End quote ---

So, does that mean that Pascal Structures natively map with C Language Structures without the need of the Directive {$packrecords c} or the Keyword packed ?

PascalDragon:

--- Quote from: domibay_hugo on January 12, 2021, 04:30:10 pm ---So, does that mean that Pascal Structures natively map with C Language Structures without the need of the Directive {$packrecords c} or the Keyword packed ?

--- End quote ---

Not necessarily. That's why the {$packrecords c} directive exists. Also packed is only a right choice if the C code enforces 1-Byte alignment as well.

In the end you always need to check what the C code does as it might use a custom alignment (this is for example the case for some structs/records on Windows where the headers enforce a different alignment than the default one and thus the Windows unit changes the {$packrecords xxx} accordingly).

Navigation

[0] Message Index

[*] Previous page

Go to full version