views:

197

answers:

2

Hi there, I've been trying to get back into coding for a while, so I figured I'd start with some simple SDL, now, without the file i/o, this compiles fine, but when I throw in the stdio code, it starts throwing errors. This I'm not sure about, I don't see any problem with the code itself, however, like I said, I might as well be a newbie, and figured I'd come here to get someone with a little more experience with this type of thing to look at it.

I guess my question boils down to: "Why doesn't this compile under Microsoft's Visual C++ 2008 Express?"

I've attached the error log at the bottom of the code snippet. Thanks in advance for any help.

#include "SDL/SDL.h"
#include "stdio.h"

int main(int argc, char *argv[])
{
    FILE *stderr;
    FILE *stdout; 

    stderr = fopen("stderr", "wb");
    stdout = fopen("stdout", "wb");

    SDL_Init(SDL_INIT_EVERYTHING);
    fprintf(stdout, "SDL INITIALIZED SUCCESSFULLY\n");
    SDL_Quit();
    fprintf(stderr, "SDL QUIT.\n");

    fclose(stderr);
    fclose(stdout);

    return 0;
}

Actual errors reported:

main.cpp(6) : error C2090: function returns array
main.cpp(6) : error C2528: '__iob_func' : pointer to reference is illegal
main.cpp(6) : error C2556: 'FILE ***__iob_func(void)' : overloaded function differs only by return type from 'FILE *__iob_func(void)'
       c:\program files\microsoft visual studio 9.0\vc\include\stdio.h(132) : see declaration of '__iob_func'
main.cpp(7) : error C2090: function returns array
main.cpp(7) : error C2528: '__iob_func' : pointer to reference is illegal
main.cpp(9) : error C2440: '=' : cannot convert from 'FILE *' to 'FILE ***'
       Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
main.cpp(10) : error C2440: '=' : cannot convert from 'FILE *' to 'FILE ***'
       Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
main.cpp(13) : error C2664: 'fprintf' : cannot convert parameter 1 from 'FILE ***' to 'FILE *'
       Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
main.cpp(15) : error C2664: 'fprintf' : cannot convert parameter 1 from 'FILE ***' to 'FILE *'
       Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
main.cpp(17) : error C2664: 'fclose' : cannot convert parameter 1 from 'FILE ***' to 'FILE *'
       Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
main.cpp(18) : error C2664: 'fclose' : cannot convert parameter 1 from 'FILE ***' to 'FILE *'
       Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
+3  A: 
#include "SDL/SDL.h"
#include "stdio.h"

int main(int argc, char *argv[])
{
    FILE *stderr; //Invalid names. These are already defined by stdio.h.
    FILE *stdout; //You can't use them (portably anyway).

    stderr = fopen("stderr", "wb"); //I'm assuming you actually want files
    stdout = fopen("stdout", "wb"); //called "stderror" and "stdout".

    SDL_Init(SDL_INIT_EVERYTHING);
    fprintf(stdout, "SDL INITIALIZED SUCCESSFULLY\n");
    SDL_Quit();
    fprintf(stderr, "SDL QUIT.\n");

    fclose(stderr);
    fclose(stdout);

    return 0;
}

Try changing the names stderr and stdout to something else. I suspect the compiler is complaining because these are already defined elsewhere in the C library.

Billy ONeal
Well, I feel silly now. Worked. Thanks very much.
Anthony Clever
@Anthony Clever: If it worked, can you do me a favor and click the checkmark icon next to this post? :)
Billy ONeal
There we go, had to wait for it to let me.
Anthony Clever
@Anthony Clever: Thank you :D
Billy ONeal
+1  A: 
  1. You don't need to declare, open, or close stdin, stdout or stderr, that's already done for you in stdio.
  2. If you're using C++, why not iostream?
tzaman