Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Example of Visual C++ nonconformant code?

What are some examples of code that are not standards compliant when using visual C++? Something that is allowed to compile under visual C++ but nothing else.

like image 899
Marlon Avatar asked Jan 30 '11 22:01

Marlon


4 Answers

You can find all the Microsoft language extensions here; you may also want to have a look to the areas of the language where VC++ is not compliant to the standard.

One that I thought was standard (I noticed it when I enabled the /Za switch) is the "magic l-value cast":

char *p;
(( int * ) p )++; 
like image 83
Matteo Italia Avatar answered Nov 10 '22 08:11

Matteo Italia


Some version of Visual C++ accept to pass non-const reference to temporary object. Something like that :

void DoSomething(std::string& str);

void NonConformantFunction()
{
    DoSomething("Temporary std::string created here");
}
like image 26
Sylvain Defresne Avatar answered Nov 10 '22 08:11

Sylvain Defresne


"Something that is allowed to compile under visual C++ but nothing else"

and

"code that are not standards compliant"

do not describe exactly the same thing. A compiler may be fully standard compliant while having extensions that are unique to that compiler, while a non-compliance is something explicitly prohibited by the standard. There is also a number of "undefined" or "implementation defined" parts of the ISO standard that might prevent portability without being non-compliant. Moreover many supported extensions are supported by other compilers so are examples of one of your constraints but not the other.

Now that said, the major extension of VC++ that would render its code non-portable are all of the C++/CLI extensions, and therefore also the .NET Framework class library which requires them.

like image 28
Clifford Avatar answered Nov 10 '22 07:11

Clifford


There is an official page on microsoft.com saying what are the parts where VC++ is not compatible with the standard. However a different issue is where it is compatible by default with the standard. For example the default scope for for variables is still wrong in VC++2010.

like image 1
6502 Avatar answered Nov 10 '22 06:11

6502