Translating to C++

Messages in english

Modérateur : xcasadmin

belanger
Messages : 59
Inscription : jeu. juil. 27, 2017 3:26 pm

Translating to C++

Message par belanger » lun. mars 18, 2019 9:15 pm

The manual (https://www-fourier.ujf-grenoble.fr/~pa ... r1118.html)
discusses translating Xcas programs into C++ programs, and gives an example
truc(n:integer) := {return 2*n+1;}
then
cpp(truc)

When I try that, I get the message
File giac_truc.cpp created.
Running indent -br -brf -l256 giac_truc.cpp
Running
c++ -I.. -I. -fPIC -DPIC -g -O2 -c giac_truc.cpp -o giac_truc.lo
Unable to compile, please fix cpp file
The file giac_truc.cpp is there (I've attached a copy, it's a bit different than the manual version),
and when I try
c++ -I.. -I. -fPIC -DPIC -g -O2 -c giac_truc.cpp -o giac_truc.lo
from the command line, I get
[~]> c++ -I.. -I. -fPIC -DPIC -g -O2 -c giac_truc.cpp -o giac_truc.lo
giac_truc.cpp: In function ‘giac::gen giac::truc(long int, const giac::context*)’:
giac_truc.cpp:13:24: error: expected primary-expression before ‘return’
giac::makevecteur (return 2 * n_i + 1)
^~~~~~
giac_truc.cpp:14:3: warning: no return statement in function returning non-void [-Wreturn-type]
}
^

How can I fix the cpp file?

Jay
Pièces jointes
giac_truc.zip
(582 octets) Téléchargé 86 fois

parisse
Messages : 5739
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: Translating to C++

Message par parisse » mer. mars 20, 2019 5:32 pm

return should be before makevecteur, not inside. I must fix something in the C translator. Perhaps the best is not to translate this chapter, it's still experimental.

Répondre