•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 423,223 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,923 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser: Programming Forums
Views: 479 | Replies: 7
![]() |
C Syntax (Toggle Plain Text)
FILE* f = NULL; fclose(f);
C Syntax (Toggle Plain Text)
FILE* f = NULL; ftell(f);
Why those functions does not return error value but terminate whole program? How can I safely tell if file is opened in C and close it???
If variable of type 'FILE*' is passed to my function I need to know the state of the file and be able to close.
Any idea?
Last edited by edek : May 9th, 2008 at 8:58 am.
> Terminates with: 'No source available for "fclose@@GLIBC_2.1() " '
You get these in debug builds because the code for fclose uses assert() to validate the input parameters.
If you were in a debugger at the time, you'd know exactly where to start looking.
In this case, fclose() is likely to begin with
Release builds have no assert() statements, so it would just return whatever the spec says fclose() should return if passed NULL.
You get these in debug builds because the code for fclose uses assert() to validate the input parameters.
If you were in a debugger at the time, you'd know exactly where to start looking.
In this case, fclose() is likely to begin with
assert( fp != NULL );
Release builds have no assert() statements, so it would just return whatever the spec says fclose() should return if passed NULL.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
Do not PM me for help; You'll be ignored, or told to learn to read.
Do not ask me if I'm muslim - I'm not. Nor do I care about yours or anyone else's mysticism. Religion is a matrix, take the RED PILL.
Do not PM me for help; You'll be ignored, or told to learn to read.
Do not ask me if I'm muslim - I'm not. Nor do I care about yours or anyone else's mysticism. Religion is a matrix, take the RED PILL.
•
•
•
•
Release builds have no assert() statements, so it would just return whatever the spec says fclose() should return if passed NULL.
Actually, it terminates in release build. It should return error value, though. It might be some internal inconsistency of the implementation of C lib I am using (glibc2.1).
Last edited by edek : May 10th, 2008 at 8:29 am.
> Actually, it terminates in release build.
Is that because it detected NULL and cleanly exited, or dereferenced NULL and bombed?
Is that because it detected NULL and cleanly exited, or dereferenced NULL and bombed?
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
Do not PM me for help; You'll be ignored, or told to learn to read.
Do not ask me if I'm muslim - I'm not. Nor do I care about yours or anyone else's mysticism. Religion is a matrix, take the RED PILL.
Do not PM me for help; You'll be ignored, or told to learn to read.
Do not ask me if I'm muslim - I'm not. Nor do I care about yours or anyone else's mysticism. Religion is a matrix, take the RED PILL.
I've found something like (http://www.stanford.edu/~thathoo/cur...io.h/code.html line 204):
What does
C Syntax (Toggle Plain Text)
/*This function is a possible cancellation point and therefore not marked with __THROW. */ extern int fclose (FILE *__stream);
'function is a possible cancellation point' mean?? Does it mean that it can cancel whole application on error? Last edited by edek : May 10th, 2008 at 1:21 pm.
![]() |
•
•
•
•
•
•
•
•
DaniWeb C Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- Read integers from a file (C++)
- how to read a text file backwards? (C)
- C Program where gets(), getchar(), are not working. (C)
- functions in header files (C++)
- how do i parse a custom delimited file (C++)
- C file stream (C)
- help with null terminated strings (C)
- Passing char * to function and populating inside (C++)
- reading a file into code (Java)
Other Threads in the C Forum
- Previous Thread: Stable marriage
- Next Thread: Unstable Program



Linear Mode