LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   C IDE which ignores C99? (http://www.linuxquestions.org/questions/programming-9/c-ide-which-ignores-c99-813776/)

searching_for_answers 06-12-2010 06:46 PM

C IDE which ignores C99?
 
Is there an IDE where I can write ANSI-C without complains and failures except ideone.com? Already tried NetBeans. I need it for K&R.

Sergei Steshenko 06-12-2010 08:34 PM

Quote:

Originally Posted by searching_for_answers (Post 4001532)
Is there an IDE where I can write ASCI-C without complains and failures except ideone.com? Already tried NetBeans. I need it for K&R.

Isn't the behavior determined by the compiler switches ?

I do not use IDEs, but from command line that's the case.

And, IIRC, K&R != C89 - the latter is ANSI "C".

graemef 06-12-2010 09:44 PM

As Sergei has said this has nothing to do with the IDE, rather the setting that you use for the compiler. Assuming that you are using gcc (or the IDE is) check the man pages to understand the most appropriate settings for your needs. Here is an online version which can be easier to navigate, look for -std= option.

searching_for_answers 06-13-2010 08:18 AM

Quote:

Originally Posted by Sergei Steshenko (Post 4001601)
Isn't the behavior determined by the compiler switches ?

I do not use IDEs, but from command line that's the case.

k


Quote:

And, IIRC, K&R != C89 - the latter is ANSI "C".
If (IIRC == "If I recall correctly")
C89 = "ANSI C";
printf("I don't understand what you're trying to say\n");

searching_for_answers 06-13-2010 08:27 AM

Quote:

Originally Posted by graemef (Post 4001642)
As Sergei has said this has nothing to do with the IDE, rather the setting that you use for the compiler. Assuming that you are using gcc (or the IDE is) check the man pages to understand the most appropriate settings for your needs. Here is an online version which can be easier to navigate, look for -std= option.

Code:

$gcc -std=c89
?
If that that is correct will it do any harm to Ubuntu since it uses C in other apps?

graemef 06-13-2010 09:11 AM

compiling a program with an earlier C standard and then running it on Ubuntu will be fine. compiling Ubuntu using the old standard will most likely give you grief.

searching_for_answers 06-13-2010 09:29 AM

Quote:

Originally Posted by graemef (Post 4002003)
compiling a program with an earlier C standard and then running it on Ubuntu will be fine. compiling Ubuntu using the old standard will most likely give you grief.

So it works but I should not recompile Ubuntu before I change it back?

Sergei Steshenko 06-13-2010 10:46 AM

Quote:

Originally Posted by searching_for_answers (Post 4001974)
Code:

$gcc -std=c89
?
If that that is correct will it do any harm to Ubuntu since it uses C in other apps?

Compiling a new application has nothing to do wit already compiled ones.

Yes, ANSI "C" is also known as C89, so '-std=c89' is what you need.

searching_for_answers 06-13-2010 11:27 AM

Solution
 
Code:

mattias@SNAR-PC-01:~/NetBeansProjects/Charater Counting$ cat programmet.c
#include<stdio.h>
main(){
    long nc;
    int c;
    nc = 0;
    while((c = getchar()) !=EOF)
        nc++;
    printf("%1d\n", nc);

Code:

mattias@SNAR-PC-01:~/NetBeansProjects/Charater Counting$ gcc -std=c89 -g -Wall programmet.c
programmet.c:2: warning: return type defaults to ‘int’
programmet.c: In function ‘main’:
programmet.c:8: warning: format ‘%1d’ expects type ‘int’, but argument 2 has type ‘long int’
programmet.c:9: warning: control reaches end of non-void function

Compiles it and -g add support for debugging and -wall will generate warnings. a.out is now created in the same directory as programmet.c

Code:

mattias@SNAR-PC-01:~/NetBeansProjects/Charater Counting$ ./a.out
Type this to run it.

This solves the thread but in the process I discovered that I actually don't need an ANSI-C IDE because there is nothing wrong with the code so far. EOF is Ctrl D not '\n'(enter) which I thought it was :redface:
FAIL


ideone.com is probably not ANSI-C the EOF is submit which explains why it works better than NetBeans.

Sergei Steshenko 06-13-2010 11:55 AM

Quote:

Originally Posted by searching_for_answers (Post 4002107)
...in the process I discovered that I actually don't need an ANSI-C IDE because there is nothing wrong with the code so far. ...
...


First of all, the wrong thing is your understanding of programming reality - as long as you see compiler warning and do nothing about them, thinking nothing is wrong with your code, your understanding of programming reality is wrong.

The very basic principle is: first make the code formally correct, i.e. with zero compiler warnings, and only then it might work.


All times are GMT -5. The time now is 01:56 AM.