Re: GCC: fclose() Error

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



g sobers wrote:
Greetings.

I seek assistance with a GCC-related source of error, which is illustrated with the help of sample code below:

1) FILE * f; 2) f = fopen(argv[1], "r");
3) fclose(f);
4) FILE * f1;
5) f1 = fopen(argv[1], "r");
6) while ((c = fgetc(f)) != EOF){
...
...


As you will notice in the sequence of steps in the illustrative code above, in line 6 a fgetc() call to file 'f' is made instead of 'f1'. This situation, a cause of segmentation fault on a non-Cygwin machine, was not encountered by Cygin's gcc compiler. In fact, the code compiles and runs successfully on Cygwin.

Would appreciate assistance with addressing the situation.


The best approach is to fix your program so that it doesn't use 'f' after it has been closed. It is not really related to gcc, but just good practice in general.

David Daney

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux