[fpc-pascal] How to translate this union ?
Ludo Brands
ludo.brands at free.fr
Sat Apr 30 10:53:20 CEST 2011
Using macros, the translation looks like
{$MACRO ON}
{$ifndef DOCUMENTATION_ONLY}
{$if SU_HAVE_SOCKADDR_SA_LEN <>0}
{$define su_len:=su_sa.sa_len}
{$else}
{$define su_len:=su_array[0]}
{$endif}
{$define su_family:=su_sa.sa_family}
{$define su_port:=su_sin.sin_port}
{$define su_scope_id:=su_array32[6]}
{$endif}
type
su_sockaddr_u = record
case longint of
{$ifdef DOCUMENTATION_ONLY}
0 : ( su_len : byte );
1 : ( su_family : byte );
2 : ( su_port : word );
{$else}
3 : ( su_dummy : smallint );
{$endif}
4 : ( su_array : array[0..31] of char );
5 : ( su_array16 : array[0..15] of word );
6 : ( su_array32 : array[0..7] of longword );
7 : ( su_sa : sockaddr );
8 : ( su_sin : sockaddr_in );
{$if SU_HAVE_IN6 <>0}
9 : ( su_sin6 : sockaddr_in6 );
{$endif}
{$ifdef DOCUMENTATION_ONLY}
10 : ( su_scope_id : longword );
{$endif}
end;
-----Message d'origine-----
De : fpc-pascal-bounces at lists.freepascal.org
[mailto:fpc-pascal-bounces at lists.freepascal.org] De la part de Ludo Brands
Envoyé : samedi 30 avril 2011 10:29
À : 'FPC-Pascal users discussions'
Objet : RE : RE : [fpc-pascal] How to translate this union ?
Forget my previous reply. I found the original header file on sourceforge.
I have alse a better understanding now of what the code is supposed to do:
in case DOCUMENTATION_ONLY is not defined, a reference to, for example,
su_sockaddr_u.su_family will be subsstituted by
su_sockaddr_u.susa.sa_family.
You could use macros and do a {$define su_family:=susa.sa_family} with the
following limitations:
- if you have variables or other record members named su_family, not part of
the su_sockaddr_u record, they will be renamed also.
- it works only for the units that include your .inc file.
-----Message d'origine-----
De : fpc-pascal-bounces at lists.freepascal.org
[mailto:fpc-pascal-bounces at lists.freepascal.org] De la part de Ludo Brands
Envoyé : samedi 30 avril 2011 09:18
À : 'FPC-Pascal users discussions'
Objet : RE : [fpc-pascal] How to translate this union ?
Can you post the original c code? You point to a file that seems to be a
reworked output from h2pas. As it is now, it indeed doesn't make any sense.
I would think the su_len,su_family,su_port should make up a record but they
aren't.
I suggest you move the #defines inside the union declaration to somewhere
before the union declaration. It'll double up the ifdef's but make the code
so much more readable.
-----Message d'origine-----
De : fpc-pascal-bounces at lists.freepascal.org
[mailto:fpc-pascal-bounces at lists.freepascal.org] De la part de ik
Envoyé : vendredi 29 avril 2011 22:15
À : FPC-Pascal users discussions
Objet : [fpc-pascal] How to translate this union ?
Hello list,
I'm trying to translate the following
<https://github.com/ik5/sofia-sip/blob/master/src/lib/sui.inc#L199> union to
Pascal, but I do not understand it, and so does h2pas.
How to translate it ?
Thanks,
Ido
LINESIP - Opening the source for communication
http://www.linesip.com
http://www.linesip.co.il
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20110430/f59acb03/attachment.html>
More information about the fpc-pascal
mailing list