473,508 Members | 2,454 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

bug of vs2k5?

Hi all. I am working on some string manipulation, and I want the passed
in string pointer to be checked. So I use "assert" to assure that. But
the C compiler of Visual Studio 2005 fails to compile that, if there's
a variable declaration after an assertion in a function(except for the
"main" function).

Here goes the code,
/************************begin of test code**********************/
#include <stdio.h>
#include <assert.h>

char *donothing(char *test)
{
assert(test!=NULL);
int a;

return test;
}

int main()
{
char *str = "abc";
donothing(str);

return 0;
}
/**************************end of test code********************/

The same code can be compiled successfully by GCC. I don't know if this
has been fixed in Service Pack 1 of Visual Studio 2005. And I am
wondering the result of Visual C++ 6.0 and Visual Studio.net 2003.

Dec 27 '06 #1
4 1322

"abracadabra" <je*********@yahoo.comwrote in message
news:11*********************@f1g2000cwa.googlegrou ps.com...
Hi all. I am working on some string manipulation, and I want the passed
in string pointer to be checked. So I use "assert" to assure that. But
the C compiler of Visual Studio 2005 fails to compile that, if there's
a variable declaration after an assertion in a function(except for the
"main" function).
The C compiler in Visual Studio 2005 conforms (mostly) with the
ISO/ANSI C Standard 9899:1990. This standard does not allow variable
declarations other than at the beginning of a block or at file scope.

Your code violates this standard.

Move your declaration of 'int a' to the beginning of the 'donothing()'
function, and it will compile.
Here goes the code,
/************************begin of test code**********************/
#include <stdio.h>
#include <assert.h>

char *donothing(char *test)
{
assert(test!=NULL);
int a;

return test;
}

int main()
{
char *str = "abc";
donothing(str);

return 0;
}
/**************************end of test code********************/

The same code can be compiled successfully by GCC.
That's because of one of two possibilites:
1) GCC supplies an extension to the C90 language which allows the above
code.
2) Later versions of GCC support the newer (1999) C standard, which
does support variable declarations as above.

Check the documentation and the options you're using with that compiler.
I don't know if this
has been fixed in Service Pack 1 of Visual Studio 2005.
There's nothing to fix with regard to your above code and that compiler.
The compiler correctly reported the error.
And I am
wondering the result of Visual C++ 6.0 and Visual Studio.net 2003.
The C compiler provided with Visual C++ will give the same result.
I have no experience with Visual Studio .NET. I don't know if it
supports C99 or not.

Finally, note that the C++ language does support what you're
doing, and that this newsgroup is for discussion of the C++ language,
not the C language, the fact that most C++ packages contain C compilers
notwithstanding.

-Mike
Dec 27 '06 #2
Thanks a lot. I've corrected this by moving the declaration to the
beginning. After changing the postfix from ".c" to ".cpp", the code
compiles. This support your point of C++. Maybe GCC makes an extension
to C99 in this case. There's no warning/error like "missing ';' before
'type'...", even gcc -Wall is specified.

Dec 27 '06 #3
abracadabra wrote:
Maybe GCC makes an extension
to C99 in this case. There's no warning/error like "missing ';' before
'type'...", even gcc -Wall is specified.
Yes, GCC has an extension that allows such declarations. It is not an
extension to C99 though, since C99 specifically allows them as well. It
is an extension to C89/90.

If you use GCC with '-ansi -pedantic' it will give you a warning about
that (maybe just '-pedantic' is enough, I don't remember exactly). Just
'-Wall' is not enough.

--
Best regards,
Andrey Tarasevich

Dec 27 '06 #4
"abracadabra" <je*********@yahoo.comwrites:
Thanks a lot. I've corrected this by moving the declaration to the
beginning. After changing the postfix from ".c" to ".cpp", the code
compiles. This support your point of C++. Maybe GCC makes an extension
to C99 in this case. There's no warning/error like "missing ';' before
'type'...", even gcc -Wall is specified.
I think you have to add -ansi to remove GNU extensions in GCC.

--
John L. Fjellstad
web: http://www.fjellstad.org/ Quis custodiet ipsos custodes
Replace YEAR with current four digit year
Dec 27 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
838
by: Tom | last post by:
Hi all In an attempt to create something like http://www.mswcf.com/issues/distributedsystemdesigner/1.gif from http://msdn.microsoft.com/msdnmag/issues/04/07/whitehorse/default.aspx I've...
2
1109
by: Christopher | last post by:
Greetings, By default Visual Studio 2005 starts each new project up with the code in partial class form. Is there anyway I can change this behavior so that the code is not split amongst...
1
1277
by: Bob | last post by:
When debugging .Net in disassembly view with vs2k5 is there any way to view memory values using segments? I tried using quickwatch and also dropping the segment/pointer in to the memory window...
3
1987
by: Brett Romero | last post by:
Does MS have a webpage listing what each icon in the VS 2K5 IDE means? Seems as though there was one of these for 2K3. I can't find anything for 2K5. Also, is there still a visual studio...
3
1373
by: rodchar | last post by:
hey all, in vs2k3 i could loop thru all the elements in the document like the following: function getscrollvalue(){ elm=document.Form1.elements; for(i=0;i<elm.length;i++) if(elm.type=="text" &&...
2
1235
by: rodchar | last post by:
hey all, i'm installing iis on my dev machine which has vs2k5 on it. will this be a problem? thanks, rodchar
0
1198
by: Quantum | last post by:
Hi there, I've got a VS2K5 project in the folder: c:\BigProject\Windows\ However, I've got all the source in this folder: c:\BigProject\Independent\
4
1466
by: SteveW | last post by:
Now that vista and the 3.0 framework are gold, I'm a bit confused, so any clarification would be very helpful. The 3.0 framework is gold and is downloadable etc. What is not 'gold' and...
3
1570
by: =?Utf-8?B?QWRpbCBBa3JhbQ==?= | last post by:
I posted this question in vsnet.ide newsgroup about more than a week back but didn't get any single response yet therefore, reposting again same to several newsgroups. When I run my C#...
8
1359
by: Ross Culver | last post by:
I'm about to get a new computer for VS2K5 development. Is it ok to get Vista yet or should I stick with XP? Thanks, Ross
0
7333
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7398
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5637
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5057
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4716
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3208
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3194
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
769
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
428
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.