Sponsored Content
Top Forums Programming C fdopen with and without -ansi Post 303024644 by migurus on Saturday 13th of October 2018 08:15:49 PM
Old 10-13-2018
C fdopen with and without -ansi

I have very little experience with gcc compilation under different environments, so please bear with me. I carried over 20 years old project into Ubuntu 18.04, it has old style K&R parameters, no function declarations to speak of, many functions without return are not declared void, and on and on...
I did a bit of cleanup and I realized that if I use -ansi then my compilation is almost 100% clean. But one simple routine complains about fdopen when I specify -ansi, without -ansi there is no complains.


Here is the code:
Code:
  $ cat f.c  
#include <stdio.h>  
#include <stdlib.h>   

FILE * my_tester(char *fname, int pnum) 
{   
  int    fd;   
  FILE *fp;      
    sprintf(fname, "/tmp/PRS.%05i.XXXXXX", pnum);         
    fd = mkstemp(fname);     
    if(fd < 0) 
    {    
         return(NULL); 
    }         
    if((fp = fdopen(fd, "w")) == NULL)     
    {         
        return(NULL);     
    }
     return(fp); 
}


Here is my compilation attempt:
Code:
  
$ cc -c -o f.o f.c  
$  
$ cc -ansi -c -o f.o f.c f.c:
 In function ‘my_tester': f.c:15:16: warning: assignment makes pointer from integer without a cast [-Wint-conversion]          if((fp = fdopen(fd, "w")) == NULL) 
$

I'd appreciate suggestions on what would be reasonable set of compiler flags. A simple C standards documentation covering those flags and those __USE_ macros would be much appreciated

Last edited by migurus; 10-13-2018 at 09:21 PM.. Reason: cut/paste did not work in Linux/Firefox, had to boot windows and make it readable in Chrome
 

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
tapset::ansi(3stap)													       tapset::ansi(3stap)

NAME
tapset::ansi - systemtap ansi tapset DESCRIPTION
ansi_clear_screen Move cursor to top left and clear screen. See function::ansi_clear_screen(3stap) for details. ansi_set_color Set the ansi Select Graphic Rendition mode. See function::ansi_set_color(3stap) for details. ansi_set_color2 Set the ansi Select Graphic Rendition mode. See function::ansi_set_color2(3stap) for details. ansi_set_color3 Set the ansi Select Graphic Rendition mode. See function::ansi_set_color3(3stap) for details. ansi_reset_color Resets Select Graphic Rendition mode. See function::ansi_reset_color(3stap) for details. ansi_new_line Move cursor to new line. See function::ansi_new_line(3stap) for details. ansi_cursor_move Move cursor to new coordinates. See function::ansi_cursor_move(3stap) for details. ansi_cursor_hide Hides the cursor. See function::ansi_cursor_hide(3stap) for details. ansi_cursor_save Saves the cursor position. See function::ansi_cursor_save(3stap) for details. ansi_cursor_restore Restores a previously saved cursor position. See function::ansi_cursor_restore(3stap) for details. ansi_cursor_show Shows the cursor. See function::ansi_cursor_show(3stap) for details. SEE ALSO
function::ansi_clear_screen(3stap), function::ansi_set_color(3stap), function::ansi_set_color2(3stap), function::ansi_set_color3(3stap), function::ansi_reset_color(3stap), function::ansi_new_line(3stap), function::ansi_cursor_move(3stap), function::ansi_cursor_hide(3stap), function::ansi_cursor_save(3stap), function::ansi_cursor_restore(3stap), function::ansi_cursor_show(3stap), stap(1), stapprobes(3stap) IBM
--- tapset::ansi(3stap)
All times are GMT -4. The time now is 03:35 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy