Hi! I'm new (started trying to understand C this morning), and have been trying to modify Perl (the compiler, not a script) to not only output a message when a script fails to run, but also do delete the offending perl script.
This is the bit of the compiler I am trying to change (version 5.8.8.r5) - Bold is what I changed.
1 2 3 4 5 6 7 8 9 10 11 12 13
#else
if (yyparse() || PL_error_count)
{
printf("Eulogize about the failed script.\n");
//Add a function to delete the script here (any tips appreciated)if (PL_minus_c) {
Perl_croak(aTHX_ "%s had compilation errors.\n", PL_origfilename);
}
else {
Perl_croak(aTHX_ "Execution of %s aborted due to compilation errors.\n",
PL_origfilename);
}
}
When I compile:
perl.c:2211: warning: statement with no effect
perl.c:2211: error: expected ';' before '_printf_'
Any help would be very much appreciated! Thanks!
-kylespitz
I think that the #else is used as a preprocessor directive for the gcc compiler I'm using (gentoo linux).
regarding printf() being redefined, I have trouble including stdio.h in the includes, I've tried:
1 2
#include <stdio> //and then also
#include <iostream> // though I didn't use them together at the same time
i eventually had to use #include </sys/include/stdio.h>
to have that line compile without error.
As a workaround, because printf() has probably been redefined, could I define my own function - i.e. print_this_please() by copying the relevant code from sdtio.h and then defining print_this_please() at the top of my file?
If you do not have an #ifdef (or #ifndef) related to that #else then it should be removed.
To use printf, you should need to include <cstdio> . Albeit, printf is still a C function. IOStream gives you access to cout that should be used to output to the screen instead.
also, i tried making my own function name without defining it elsewhere --> aww_shoot_printf() and got an implicit declaration of function error. i think that means that printf() and fprintf() should work right? perhaps it's a syntax error?
gentoo linux, it's a version of linux where just about everything needs to be configured by hand, so I wouldn't be surprised at all if I screwed something up.
also i just tried writing a hello world program from a different directory. The compiler couldn't find iostream this way either! it would make sense that the directories are messed up, where should I be able to find iostream.h or any of the other libraries?
if I #include <stdio.h> then my compiler finds it just fine.
however, it still doesn't seem to like printf when I compile perl.c
my hello world program worked just fine (after I found stdio.h and fixed the compiler). I:
which output hello world just fine. but when i do the same thing with perl.c it doesn't seem to work., i get the same, "expected a ';' before _printf_" error as before.
g++ --version returned the same result as gcc --version. It looks like g++ and gcc are the same compiler (both have the same copyright and library information)
that printf is the only on in the if statement:
#
if (yyparse() || PL_error_count)
also, i think i JUST found the problem! thank you all so much for your help!
zaita helped me find the stdio.h file i needed, and I discovered (thanks to Duoas), that printf is defined differently elsewhere - probably in one of the many #includes that are at the top of the file. printf isn't defined in the file itself.
What i discovered was that I needed to use the printf function that perl described. Once I ran a search (i'm using nano to do the edits :) I found a PerlIO_printf function. I tried to use that function earlier, but it needed more arguments than I understood. After parsing the file some more, I found a PerlIO_printf(PerlIO_stdio, MESSAGE) Basically, by passing a PerlIO_stdio function to the PerlIO_printf, I was able to have perl output anything I wanted it to.