in reply to Inline::C and NULL pointers
Here's a little program illustrating one way of using undef as a 'NULL pointer' parameter in Inline C.
use strict; use warnings; my $point = pack 'f2', 1.2, 2.3; func(\$point); func(undef); # pass in 'NULL pointer' use Inline C => <<'C_END'; typedef struct { float x, y; } Point; void func(SV *buf) { SV *point_ref = SvRV(buf); if (!point_ref) { printf("got a null pointer\n"); } else { /* dereference */ Point *point = (Point *)SvPV_nolen(point_ref); printf("x=%.2f, y=%.2f\n", point->x, point->y); } } C_END
Hope this helps.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Inline::C and NULL pointers
by etj (Priest) on Dec 19, 2021 at 15:37 UTC | |
by Chrysotoxum (Novice) on Dec 19, 2021 at 22:09 UTC | |
by etj (Priest) on Dec 27, 2021 at 08:42 UTC |