stevieb has asked for the wisdom of the Perl Monks concerning the following question:
This is more of a curiosity thing than anything as I must admit, I don't know a whole lot of C.
Can someone explain what I'm missing in the below code? In the C num() function, I have a uint8_t argument, which causes an error:
Undefined subroutine &main::num called at perl.pl line 6.
The broken code:
use warnings; use strict; use Inline 'C'; num(1); __END__ __C__ #include <stdio.h> #include <inttypes.h> void num(uint8_t number){ printf("%d\n", number); }
However, if I accept the argument as an int, and then cast it to uint8_t, it works fine:
void num(int number){ number = (uint8_t)number; printf("%d\n", number); }
The code that breaks in Perl (uint8_t in the function definition) works fine when compiling/running it as a straight up C program.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Inline::C Undefined subroutine with uint8_t C function parameter
by BrowserUk (Patriarch) on Jan 09, 2017 at 21:41 UTC | |
by stevieb (Canon) on Jan 09, 2017 at 21:45 UTC |