Bill Allombert on Sun, 01 Apr 2018 11:30:10 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: main: bug in PARI/GP (Segmentation Fault), please report.


On Sun, Apr 01, 2018 at 12:08:39AM -0400, David Bernier wrote:
> In a project led by Dr Tao of UCLA, we are trying to use gp2c in the form:
> 
> "gp2c-run main.gp", main.gp being a GP script. (to compile a *.gp script).

Hello David,

There are two issues that cause problems for gp2c:

1) "main" is a reserved function name in C.

You can either rename "main" to something else or use the flag -pmy_ so
gp2c to do it for you transparently.

2) You use global variables. For gp2c to know about them, you need
to either use global(...) or initialize them at the start of the file,
which you do, except that you forgot about abb at least.

Also in this case you have to run the initialization code before calling
the main function as follow (on the same line!).
init_main();main()

Some general advices: 

1) Use the gp2c flag -W to get warnings.
In this case you will get lots of warnings about undeclared variables.
Declare them with global() or my() as the case may be.

2) Use the flag -g so that gp2c will perform garbage collection to save
memory.

So in your case, do

1) add "abb=0;" at the start of the script
2) run "gp2c-run -gW -pmy_ main.gp"
3) do in GP "init_main();main()"
4) eventually, fix the warnings.

Finally, I suggest you read the tutorial at
https://pari.math.u-bordeaux.fr/pub/pari/manuals/gp2c/gp2c.html

Thanks for using GP2C!
Bill.