Header translating. A bit long

From: Nikola Jankovic (news_jn_at_yahoo.com)
Date: 10/31/03


Date: Fri, 31 Oct 2003 12:33:06 +0100

I've been translating headers for libsndfile
(http://www.zip.com.au/~erikd/libsndfile) to Delphi/Object Pascal, and I
think I'm almost there, thanks to Robert Marquardt (Team JEDI).
The last thing to check is to see if the structs/records are packed or not.

I've written progs in Delphi and in C to output the sizeof of the
structures. I got the same results (for Delphi and C), but I must admit
that I don't understand completely the results.

There are 4 records:
1)
SF_INFO = record
  frames: int64;
  samplerate,channels,format,sections,seekable: integer;
end;
Total of 5x4B + 8B = 28B and sizeof gives 32. Probably because the default
alignment is 8 in both langs (4 added bytes are at the _end_ of the
structure (I've written some my values and output the structure to the
file, tried that in C, using original header file). So, added bytes for the
alignement are added to the end of the structure, to the last field?). This
is non-packed?

2) and 3)

  SF_FORMAT_INFO = record
    format: Integer;
    name, extension: PChar;
  end;

  SF_DITHER_INFO = record
    type_: Integer;
    level: Double;
    name: PChar;
  end;
These two I'm not sure about since they give sizes of 12 and 24
respectively. 3x4 and 4+8+?

4)
  SF_EMBED_FILE_INFO = record
    offset, length: sf_count_t;
  end;
Delphi help: "If two fields share a common type specification,
they are packed even if the declaration does not include the
packed modifier and the record type is not declared in the
{$A-} state." Does C do the same thing? Sizeof gives expected 16 anyway.

So my question really is which of these are packed and which are not?

Thanks in advance
Nikola



Relevant Pages

  • Re: TAudioIO SNAFU, arrgh ak, splutter.
    ... I may need to do a re-installination of Delphi 7. ... Put the component in a package of its own and then compile and install that package. ... So FPaused is declared in an ancestor of whatever class is declaring this published property? ... You'll get that by looking at the declaration of TBufferEvent; ctrl+click on that identifier in the OnFillBuffer property declaration you quoted above. ...
    (alt.comp.lang.borland-delphi)
  • Re: ANN: CodeHealer 2.1.1 now available
    ... of problems CodeHealer can fix. ... CodeHealer can detect significantly more issues than it can ... issues that later versions of Delphi also detects, ... commenting out the item declaration or deleting it completely, ...
    (borland.public.delphi.thirdpartytools.general)
  • Re: Borland snubbing out the hobbyist programmers with Delphi 2005
    ... That dose *not* mean making Delphi over in VB's image. ... > I would agree with you that introducing new keywords in Delphi always ... It appears Diamondback would give me this same "feature" by using automatic ... some clue in the variable name so the automatic declaration would be ...
    (borland.public.delphi.non-technical)
  • Re: Large public source archives? Delphi file extensions?
    ... I tried it on some of my Delphi sources and if found only unhelpfull stuff. ... It is also very common that an interface declaration and the declaration ... apparently think cut'n'paste is a good form of code reuse. ...
    (borland.public.delphi.language.objectpascal)
  • Convert a dll call from vb to Delphi
    ... I need to convert a declaration and a call of a vb dll to delphi. ... In vb, the source correct code for declaration and use, is this: ... ByRef lpChannelID As Long) As Long ...
    (borland.public.delphi.language.objectpascal)