Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: c/c++
command line option "-std=c++0x" is valid for C++/ObjC++ but not for C...what's this about?
Posted 27-Sep-12 6:31am
Comments
Richard MacCutchan at 27-Sep-12 11:57am
   
C does not support C++.
Sandeep Mewara at 27-Sep-12 12:16pm
   
Should not this be an answer?
Richard MacCutchan at 27-Sep-12 12:25pm
   
Probably, but I did not verify it anywhere.
Akhilesh Halageri at 27-Sep-12 12:48pm
   
This is the program i wrote and got the warning, what in this is strictly not a part of C?
#include
#include
#include
#include"stackADTs.h"
bool pity_lessOReq(char *c,char ca)
{
if((ca=='*'||ca=='/')&&(*c=='+'||*c=='-'))
return false;
else
return true;
 
}
int main()
{
int i=0;
STACK *stack;
char q[20]={0},ch,*chP1,*chP2,*chP3;
FILE *p;
stack=create_stack();
p=fopen("boo1.txt","w");
if(!p)
{
printf("ERROR, could not find the file\n");
exit(0);
}
printf("Enter a balanced infix expression\n");
while((ch=getchar())!=EOF)
fputc(ch,p);
fclose(p);
p=fopen("boo1.txt","r");
while((ch=fgetc(p))!=EOF)
{
if(ch=='(')
continue;
else if(ch=='a'||ch=='b'||ch=='c'||ch=='x'||ch=='y'||ch=='z')
q[i++]=ch;
else if(ch=='*'||ch=='/'||ch=='+'||ch=='-')
{
chP1=(char *)malloc(sizeof(char));
*chP1=ch;
if(!empty_stack(stack))
{
chP2=(char*)pop_stack(stack);
if(pity_lessOReq(chP2,ch))
{
push_stack(stack,chP1);
push_stack(stack,chP2);
}
else
{
push_stack(stack,chP2);
push_stack(stack,chP1);
}
}
else
push_stack(stack,chP1);
}
if(ch==')')
{
chP3=(char*)pop_stack(stack);
q[i++]=*chP3;
}
}
printf("The PostFix expression is : %s",q);
destroy_stack(stack);
return 0;
}
Richard MacCutchan at 27-Sep-12 12:55pm
   
You told the compiler to apply std=c++0x, but this program is C not C++ so the option is not valid.
Akhilesh Halageri at 27-Sep-12 12:58pm
   
but the extension is .c, why should that matter??
Sergey Alexandrovich Kryukov at 27-Sep-12 13:03pm
   
Ask it yourself. C is unrelated to this option.
--SA
Akhilesh Halageri at 27-Sep-12 13:05pm
   
thats what i mean, when its unrelated why does the compiler enforce C++ standards on a program that isn't in C++?
Sergey Alexandrovich Kryukov at 27-Sep-12 13:07pm
   
Ask a compiler... :-)
I don't see why do you consider this unreasonable. You said that the option is not valid for C, didn't you? But why on Earth should it be valid?
--SA
Akhilesh Halageri at 27-Sep-12 13:10pm
   
I'm not the one who said that, twas the warning given by the compiler and i just wanted to what was it about...I'm new to programming :(
Sergey Alexandrovich Kryukov at 27-Sep-12 15:43pm
   
Being the new one does not free you form basic logic. Don't you see that the warning makes perfect sense. If not, I don't understand what are you missing...
--SA
Akhilesh Halageri at 28-Sep-12 11:33am
   
bt isnt it the compiler's job to implement C++ standards only on C++ programs? why is tht option even made available??
Akhilesh Halageri at 28-Sep-12 12:47pm
   
thanks for ur time sir :) I might ask few things which might seem lame since I'm a beginner plz dont mind
Richard MacCutchan at 27-Sep-12 15:13pm
   
You are asking the compiler to enforce C++0x standards on code that is not C++; so it responds by telling you that the option is not applicable to C code. How difficult is that to understand? It's like telling your phone company that you want to apply British rules to all your phone connections.
Akhilesh Halageri at 28-Sep-12 11:35am
   
bt isnt it the compiler's job to implement C++ standards only on C++ programs? why is tht option even made available??
Richard MacCutchan at 28-Sep-12 11:54am
   
Because the compiler will compile C++ source code or C source code. So if you are asking it to compile pure C code you should not use options that only apply to C++. This is a standard for all C/C++ compilers and has been so for years.
Akhilesh Halageri at 28-Sep-12 12:47pm
   
didn't know that its a standard...thanks for ur time sir :) I might ask few things which might seem lame since I'm a beginner plz dont mind
Richard MacCutchan at 28-Sep-12 13:40pm
   
No problem. But, as a beginner it is always worth spending some time learning about the standards as well as the language etc. You can find out quite a lot on MSDN, and also on Bjarne Stroustrup's website.
Sergey Alexandrovich Kryukov at 27-Sep-12 13:02pm
   
Absolutely right. C++0x is the obsolete name of what is called C++11:
http://en.wikipedia.org/wiki/C%2B%2B0x
 
It is not applicable to C
--SA

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Is it about gcc?
If so, gcc is a frontend for several language compilers, one being C, another C++, etc.
It's your choice to pass the appropriate command line options to the compiler.
If you compile C code, use the right command line options: C++11 (or alike) are for sure not C options.
On the other hand, you might try to compile the C code with the C++ compiler.
See also CodeBlocks, GCC: change project language c and c++?[^].
 
Cheers
Andi
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 459
1 Maciej Los 325
2 Sergey Alexandrovich Kryukov 234
3 DamithSL 233
4 BillWoodruff 200
0 OriginalGriff 7,168
1 Sergey Alexandrovich Kryukov 6,377
2 DamithSL 5,461
3 Manas Bhardwaj 4,876
4 Maciej Los 4,450


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 27 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100