in reply to Using C-style .h as constants
So one way would be to modify the "make file" for your C program so that if the .h file has changed, it creates a new Perl .pm module file (that your main Perl program "uses"). You do this by writing a Perl program that reads the .h file and writes Perl code!
I personally would be thinking in the direction of a module like this rather than just another .pl file that is executed at the start of your Perl's main .pl file. You can make it very clear what is "derived from the .h file" and that would be the purpose of this Perl module - defining constants that the C program knows about.
Hope this makes sense to you.
Write a Perl program that is one of the "make targets" in the make file. That Perl program writes a Cinterface.pm module file. That file is "used" by the PerlA.pl file when it runs. If you redefine #define MAX_FILES = 20 in the .h file, then building the C program causes the Perl program to also understand that: use constant MAX_FILES => 20; and that change goes into a new version of the .pm file.
Of course instead of just running your PerlA.pl program, you need to run the "make" file of the C program first. The Perl program depends upon the .h constants of the C program. The syntax of this enum stuff can all be taken care of. Perhaps the "OH!" moment for you is that you need to write a Perl program that writes Perl code! And that Perl program is a target in the "make" file. If the .h file changes, then the Perl Cinterface.pm module (program generated) changes and therefore the .pl program that runs has been modified.
|
|---|