Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

C - freopen or freopen_s

Name: Anonymous 2014-02-08 16:01

These functions, declared inside stdio.h, both have one thing that I couldn't find the use of:


== FILE * freopen( "asd.txt", "r+", oneFILE*variable ); ==

Why does this shit return a (FILE *)?
- The oneFILE*variable gets its previously held file closed, all good.
- The oneFILE*variable gets loaded with the "asd.txt" with "r+" attribute, all good.

Then the function fucking returns the same pointer, again, the same thing that has been fucking stored inside the oneFILE*variable, why?


== errno_t freopen_s( ONEdummyFILE**variable, "asd.txt", "r+", oneFILE*variable ) ==

Same shit again, why am I giving a retarded, no-use, dummy FILE** variable?

What the fuck is this? Does it have another explanation?

Name: Anonymous 2014-02-08 16:27

Try SFIO, a STDIO alternative.
http://www2.research.att.com/~astopen/download/tgz/sfio.2005-02-01.tgz
 When prompted for license agreement authorization use this User Name:

    I accept www.opensource.org/licenses/eclipse

and this Password:

    .

Name: Anonymous 2014-02-08 17:47

freopen_s is Microsoft's idea. No idea why they did that, but MS used macros/templates/overloads to convert normal C++ code to use the functions so they probably wanted the conversion to be as mechanical as possible. Since freopen could fail, it can return NULL.

Name: Anonymous 2014-02-08 17:59

>>1
freopen_s is a unportable shit that doesn't have reasont to exist. I think it's in the C11 standard as optional thing but only MS implements it because they were support it before the standard

Name: Anonymous 2014-02-08 19:11

>>3
freopen returning NULL when an error occurs is a good reasoning for it to have a return value, but why a return value with the 4 byte type (FILE *)? A single byte (char) would be able to do it.

Whatever, I think I'll just use freopen then, and disregard the return value, or maybe use it within "if". I don't want to create a dummy (FILE *) to pass into freopen_s.

What reply codes are here in this board? /b/ has none...
code tags perhaps

Name: Anonymous 2014-02-09 1:56

>>5
A single byte (char) would be able to do it.
Using smaller types than int or char * for function return values is a silly optimization (you'll notice that none of the functions in the standard library do it). On most architectures, a whole register is used for the return value regardless of whether you're  returning a char, an int, or a char *.

I think I'll just use freopen then, and disregard the return value
...and then your program will die horribly if anything bad happens to the file after you open it the first time.

Name: Anonymous 2014-02-09 9:15

>...and then your program will die horribly if anything bad happens to the file after you open it the first time.

Explain... I am planning to use something like this:

if ( freopen( "some.txt", "r+", someFILEpointer ) ) {
    /* do things with the file */
}
else {
    printf_s( "Your file could not be opened for writing" );
    /* don't do things with the file */
}


What bad is to happen to my file? I don't get it...

Name: Anonymous 2014-02-09 12:56

printf_s
WHAT IS WRONG WITH YOU
are you an ENTERPRICE QUALITY C PROGRAMMER?
https://dis.4chan.org/read/prog/1391623817/

Name: Anonymous 2014-02-09 19:06

>>7
Usually when somebody says they are ignoring a return value it means that they are doing nothing with it (e.g. that the resulting program would behave the same if the return value of the function whose argument is ignored is cast to void).

You are testing the return value for null there; that is perfectly fine.

>>8
And in a case where all that's really needed is puts!

Name: Anonymous 2014-02-10 14:52

>>9
Well, you're right, I should have been more explicit about what I'm ignoring.

What I was trying to say is that I will be ignoring it as a FILE pointer, while still using it a simple error indicator.

Name: Anonymous 2014-02-11 15:57

>>6
>le pedophile sage

>>9
>le pedophile sage

Don't change these.
Name: Email:
Entire Thread Thread List