If Then Trouble - expected a ';' before '_printf_'

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
'#' is used as a preprocessor directive. I do not see how you use it here.
It is being used as a preprocessor directive. He just didn't post the #if.
I suspect that printf() has been redefined somewhere.
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.

e.g
cout << "Hello World!" << endl;
the #else is defined elsewhere (I have no idea where because the problem is 5000 lines long, but it compiled fine before I added my two lines)
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?
oddly enough, when trying #include <cstdio> or <stdio> or <iostream>, I got a file not found error every time. any idea what's causing that?
I'd say that your compiler's include directories are not configured correctly.

What operating system are you running this on?
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.

my compiler:
GCC 4.1.2 (Gentoo 4.1.2 p1.0.2)

companion library:
/usr/lib/gcc/i686-pc-linux-gnu/4.1.2/libgcc.a

Ahhh ok. /sys/include isn't a standard include directory. /usr/include is :)

It maybe that GCC isn't setup to look in /sys/include by default.
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?
i found stdio.h!

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:

1
2
3
4
5
6
#include <stdio.h>

int main() {
printf ( "hello world\n" );
return 0;
}


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.

btw, zaita, thank you so much for your help.
Last edited on
It sounds like you have GCC (C) installed but not G++ (C++).
try:
g++ --version
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)
Last edited on
Quick question: Is that printf() the only one, or there are more but that's the only one causing an error?
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.
However, my real goal is to have perl delete a file when it doesn't compile. could I add a delete function using a similar syntax?
Topic archived. No new replies allowed.