Compound data type: Difference between revisions

Removed TODO tags. Simplified Perl example; it was '''way''' more complicated than necessary. This isn't an obfuscation contest.
m (Structure moved to Complex Data Type: "Structure" is somewhat ambiguous. It might be considered to refer to structured programming, function structure, syntax structure, etc.)
(Removed TODO tags. Simplified Perl example; it was '''way''' more complicated than necessary. This isn't an obfuscation contest.)
Line 75:
}
}
 
==[[D|D TODO]]==
[[Category:D]]
'''Compiler:''' [[DMD]],[[GDC]]
 
==[[Forth|Forth TODO]]==
[[Category:Forth]]
 
==[[Fortran|Fortran TODO]]==
[[Category:Fortran]]
 
==[[IDL]]==
Line 94 ⟶ 84:
;=> { 6 7}
 
==[[Java|Java TODO]]==
[[Category:Java]]
 
Line 113 ⟶ 103:
}
 
==[[JavaScript|JavaScript TODO]]==
[[Category:JavaScript]]
 
Line 120 ⟶ 110:
point.y = 2;
 
==[[JSON|JSON TODO]]==
[[Category:JSON]]
 
Line 128 ⟶ 118:
};
 
==[[Perl|Perl TODOPHP]]==
[[Category:Perl]]
'''Interpeter:''' [[Perl]]
 
# Please verify the code above... (from CPAN docs, not tested)
 
# Using Class::Struct
use Class::Struct;
struct Point => [ x => '$', y => '$' ];
my $point = new Point( x => 1, y => 2 );
 
# Using Inline::Struct with C code embedded
use Inline C;
my $point = new Inline::Struct::Point(1,2);
__C__
typedef struct Point
{
int x;
int y;
};
 
# Using Inline C, Struct
use Inline C => <<'END', ENABLE => 'STRUCTS';
struct Point {
int x;
int y;
};
END
my $point = Inline::Struct::Point->new(1,2);
print $point->x, $point->y, "\n";
 
# Using bytes packed data with pack/unpack
my $point = pack("ii", 1, 2);
my ($x, $y) = unpack("ii", $point);
 
# Using a hash for storage
my %point = ( x => 1, y => 2);
 
# Using Win32::API::Struct
use Win32::API;
Win32::API::Struct->typedef( 'Point', qw(
int x;
int y;
));
 
# Declarative
my $point = new Win32::API::Struct->new( 'Point' );
$point->{x} = 1;
$point->{y} = 2;
 
# Tie
tie %point, 'Win32::API::Struct', 'Point';
$point{x} = 1;
$point{y} = 2;
 
 
# Using C::DynaLib::Struct
use C::DynaLib::Struct;
Define C::DynaLib::Struct('Point', 'ii', [qw(x y)]);
 
# Using C::Include
use C::Include qw(point.h -cache);
my $point = $include->make_struct( 'Point' );
 
point.h:
#ifdef __PERL__
// Anything that should be parsed by C::Include only
#endif
typedef struct Point { int x; int y; } Point;
 
==[[PHP|PHP TODO]]==
[[Category:PHP]]
 
Line 225 ⟶ 142:
# => Point is {4,7}
 
==[[OCaml|OCaml TODO]]==
[[Category:OCaml]]