Sponsored Content
Top Forums Programming C fdopen with and without -ansi Post 303024673 by Don Cragun on Sunday 14th of October 2018 01:36:19 PM
Old 10-14-2018
Jim basically has it right. With gcc -ansi gcc is being asked to supply a compilation environment as specified by an ISO C Standard. You will have to look at the gcc documentation to determine which version of the ISO C Standard that compiler flag implements.

The C Standard does not contain any definition for the fdopen() function. So, if you ask the compiler to give you a C Standard conforming environment, a function prototype for fdopen() can't be included in stdio.h.

The POSIX Standards do include a function prototype for fdopen() in stdio.h. If you want to build an application that conforms to the 2008 through 2017 versions of the POSIX Standards, you need to define the _POSIX_C_SOURCE macro to have the value 200809L before any header defined by the POSIX Standard is included and use a compiler that provides a C compiler conforming to the 1999 version of the ISO C Standard. On a UNIX, Linux, or BSD based system, this would typically be done with:
Code:
c99 -D _POSIX_C_SOURCE=200809L -o f f.c

Note also that using -c and -o in the same invocation of c99 produces unspecified results. Using both (as shown in post #1 might silently ignore one of those options, might produce a diagnostic message and do nothing else, might do whatever it was that the person who used that combination wanted to happen, or might do something else entirely at the discretion of the person who wrote the code for the compiler you're using.

Note also that using cc -o f.o f.c is always wrong. By convention a file with the extension .o is an object file created from a single source file. For example, the command:
Code:
cc -c f.c

will create a file named f.o if f.c does not contain any errors and will not create a runnable file. Using the -o. If the -c option is not included on the command line, the source files named on the command line will be compiled and the object files created from those sources file and any named object files will be linked together with default and named libraries to create a runnable file. By default that runnable file will be named a.out. The name of that runnable file can be overridden using the -o option (as shown in the c99 command I suggested above).
This User Gave Thanks to Don Cragun For This Post:
 

10 More Discussions You Might Find Interesting

1. Programming

K&R vs. ANSI

To anyone that can answer this: Are the differences great between the ANSI and K&R standard? What are some of the major differences between them?? -REM (1 Reply)
Discussion started by: REM
1 Replies

2. Programming

Ansi C

Dear All, I have to develope some C functions in Unix for a Magic program. The original MSE code which compiles the attached C program uses a +z option, but the cc compiler don't know this. The complete command in the compiler script is 'cc -c -Aa +z myfile.c'. The warning message is 'The -z... (4 Replies)
Discussion started by: Frankie
4 Replies

3. Programming

ANSI C vs POSIX

can somebody explain about the ANSI C vs POSIX. say i was using open and fopen, i know that open is POSIX, and fopen is ANSI C. i read that that POSIX is a system call and ANSI C is like a standard library function. wouldn't the fopen function has to call on open function anyway to open any kind... (2 Replies)
Discussion started by: bb00y
2 Replies

4. Programming

difference between fdopen() and freopen()

hi , I came acroos two functions fdopen() and freopen(). what is the difference between these two functions and where can they be used. Is it that fdopen() is used to write freopen(). Advance Thanks for your co-operation. :) (1 Reply)
Discussion started by: kinnaree
1 Replies

5. HP-UX

ANSI / C Compiler for HP-UX 11.11

Good Day I downloaded Server Evaluation copy of C/ANSI compiler, but when I try to compile a file with it, it gives me following error - (for HP-UX 11.11 v1 PA-RISC) Internal Error: Codeword file /opt/ansic/newconfig/ansic.cwd missing or empty. Detailed Errors are as follows Internal... (3 Replies)
Discussion started by: shawnbishop
3 Replies

6. Programming

hint on ansi c

I am a student. And need help on following program. I want to make a c program. I have to scan a sentence and I have to interchange a word from that sentence. Example: Scan the sentence is " Drilling machine and Milling machine " . Replace the word "machine" by "operation". And output should... (2 Replies)
Discussion started by: dhaval chevli
2 Replies

7. Shell Programming and Scripting

Convert file from Unix - ANSI to PC - ANSI

Hi, I am creating a file in Unix using a shell script. The file is getting created in the Unix - ANSI format. My requirement is to convert it to the PC - ANSI format. Can anyone tell me how to do this? Thanks, Sunil (0 Replies)
Discussion started by: ssmallya
0 Replies

8. HP-UX

Unix_ANSI to PC-ANSI

I want to convert a file from Unix-ANSI to PC-ANSI format. How can i achieve that? (0 Replies)
Discussion started by: ssmallya
0 Replies

9. HP-UX

HP-UX ansi c precompiler

Hi, How can i find which ansi c precompiler are installed on my hp-ux b11.23 itanuim machine ? Thanks (3 Replies)
Discussion started by: yoavbe
3 Replies

10. Programming

why the implementatoin of Bakery algorithm in ANSI C does not work in ANSI C

I follow the description of wiki (Lamport's bakery algorithm - Wikipedia, the free encyclopedia), then implement that algorithm in C, but it doesn't work, Starving is still here, is the implementation worry? Only print out: Thread ID: 0 START! Thread ID: 0 END! Thread ID: 0 START!... (2 Replies)
Discussion started by: sehang
2 Replies
All times are GMT -4. The time now is 03:10 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy