Microsoft Visual Studio

I

iC and iC++

When programming in Visual Studio, i get an error like this: error
C2143: syntax error : missing ';' before 'type'

So, for example, if you have a function like:

int func(int x)
{
int y = x/4;
return y;
}

You would need to rewrite your code like this:

int func(int x)
{
int y;
y = x/4;
return y;
}

I wonder why that is and also if there is an option somewhere to turn
off.

Thanks
 
A

Alexander Bartolich

iC said:
When programming in Visual Studio, i get an error like this: error
C2143: syntax error : missing ';' before 'type'

So, for example, if you have a function like:

int func(int x)
{
int y = x/4;
return y;
}

You are not honest with us.
Please copy the real example code.

--
 
I

iC and iC++

You are not honest with us.
Please copy the real example code.

--
its just an example... my point is MVS doesnt allow you to declare
and initialize variables in one line.
 
R

Rob Kendrick

its just an example... my point is MVS doesnt allow you to declare
and initialize variables in one line.

It has whenever I've used it. Please do as Alexander asks, and provide
a minimal demonstration of this, complete with the errors the compiler
emits when given this code.

B.
 
K

Keith Thompson

iC and iC++ said:
its just an example... my point is MVS doesnt allow you to declare
and initialize variables in one line.

It almost certainly does. Both versions of the function that
you posted are perfectly legal and equivalent to each other.
Any compiler that printed the error message for either of them would
be very badly broken, and I don't believe VS is that badly broken.

By paraphrasing and re-typing your code samples, you have eliminated
the part of the code that caused the actual problem. You've also
made an assumption about the cause of the problem, an assumption
that's almost certainly incorrect. It's as if you had a machine
with a malfunctioning part, and you showed it to a mechanic asking
for help -- after removing that part.

If you post the *exact* code that's triggering the error message
(copy-and-paste it, don't try to re-type it), along with the exact
error message, we can help.

Suggested reading: <http://www.catb.org/~esr/faqs/smart-questions.html>
 
B

Ben Bacarisse

iC and iC++ said:
its just an example... my point is MVS doesnt allow you to declare
and initialize variables in one line.

That seems unlikely. MSV has a good reputation (I don't know it). Can
you post an actual example and the flags/options you use when compiling?
 
I

iC and iC++

s/almost //

<snip>

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
"Usenet is a strange place" - dmr 29 July 1999
Sig line vacant - apply within

#include <stdio.h>
#include <math.h>
#include<assert.h>

int func(int x)
{
//int y;
assert (x!=0);
int y = 4/x^2 + x/4;
return y;
}


int main ()
{
int ans = func(5);
printf("the answer is %i", ans);
getchar();
}


check this!
 
I

iC and iC++

It almost certainly does.  Both versions of the function that
you posted are perfectly legal and equivalent to each other.
Any compiler that printed the error message for either of them would
be very badly broken, and I don't believe VS is that badly broken.

By paraphrasing and re-typing your code samples, you have eliminated
the part of the code that caused the actual problem.  You've also
made an assumption about the cause of the problem, an assumption
that's almost certainly incorrect.  It's as if you had a machine
with a malfunctioning part, and you showed it to a mechanic asking
for help -- after removing that part.

If you post the *exact* code that's triggering the error message
(copy-and-paste it, don't try to re-type it), along with the exact
error message, we can help.

Suggested reading: <http://www.catb.org/~esr/faqs/smart-questions.html>

--
Keith Thompson (The_Other_Keith) (e-mail address removed)  <http://www.ghoti.net/~kst>
Nokia
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

Like I said, maybe you have the right setting on you MVS. I posted my
problem code. It would be interesting to see if it works for you.
 
I

Ian Collins

#include<stdio.h>
#include<math.h>
#include<assert.h>

int func(int x)
{
//int y;
assert (x!=0);
int y = 4/x^2 + x/4;
return y;
}

Well that's not what you posted the first time.

You are mixing statements (the assert) and declarations what C89
compilers will not accept. C99 compilers will.
 
I

iC and iC++

Well that's not what you posted the first time.

You are mixing statements (the assert) and declarations what C89
compilers will not accept. C99 compilers will.

So, MVS uses a c89 standard compiler?
I usually use Dev-C++ and I never has a problem mixing these
statements. Thanks for the input!
 
I

Ian Collins

So, MVS uses a c89 standard compiler?
Yes.

I usually use Dev-C++ and I never has a problem mixing these
statements.

I think that's based on gcc, which accepts all sorts of extensions
unless you tell it not to.
 
J

James Lothian

iC said:
#include<stdio.h>
#include<math.h>
#include<assert.h>

int func(int x)
{
//int y;
assert (x!=0);
int y = 4/x^2 + x/4;
First off, if you want to exponentiate, use the pow() library function.
The ^ operator in C is exclusive-or.
Secondly, in my newsreader, the '^2' shows up as a superscript 2. If you've
succeeded in entering that in the devstudio IDE editor, then that's almost
certainly the cause of the problem.

James
 
I

iC and iC++

James Lothian wrote:



He posted an xor symbol, not a superscript 2. My newsreader also
"translated" it into a superscript 2 in the "view message" feature, but
got it right in the "reply to message" feature. If you look at the
message source (I don't know how to do that in SeaMonkey, but in
Thunderbird it's View/Message Source), the ^ should be reported
faithfully therein.

Of course, he almost certainly doesn't want a ^, but that's another
matter entirely!

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
"Usenet is a strange place" - dmr 29 July 1999
Sig line vacant - apply within

forgive my "^".. its what i get from coding in Matlab.. but its good
to know that MVS does not confirm with C99. I believe this post has
been answered and I appreciate your input.
 
J

James Lothian

Richard said:
James Lothian wrote:



He posted an xor symbol, not a superscript 2. My newsreader also
"translated" it into a superscript 2 in the "view message" feature, but
got it right in the "reply to message" feature. If you look at the
message source (I don't know how to do that in SeaMonkey, but in
Thunderbird it's View/Message Source), the ^ should be reported
faithfully therein.
Yup, you're right. I can reproduce the original error by disabling
language extensions.

James
 
J

James Lothian

James said:
Yup, you're right. I can reproduce the original error by disabling
language extensions.

James
FWIW, switching off 'display emoticons as graphics' in
prefs/mail & news/message display prevents Seamonkey from doing this.

James
 
I

iC and iC++

FWIW, switching off 'display emoticons as graphics' in
prefs/mail & news/message display prevents Seamonkey from doing this.

James

MVS has a very difficult documentation, it takes a lot of time to get
what you are looking for. I disabled/enabled the language extension
but the error persists. I think I am going to let it go..
 
K

Keith Thompson

iC and iC++ said:
If you post the *exact* code that's triggering the error message
(copy-and-paste it, don't try to re-type it), along with the exact
error message, we can help.
[...]

Like I said, maybe you have the right setting on you MVS. I posted my
problem code. It would be interesting to see if it works for you.

I don't have MVS (Microsoft Visual Studio). My comments were based
on my knowledge of the C language.
 
P

Peter Nilsson

It compiles without error in VC++ 6.0 and in VC++ 2008 if
you remove the assertion.

Which is explained elsethread. C90 doesn't support nested
statements and declarations, C99 does.
Interestingly enough, it also compiles without errors as
written if you compile it as a test.cpp file.

As does C++.
 
B

blmblm

[ snip ]
its just an example... my point is MVS doesnt allow you to declare
and initialize variables in one line.

Huh? what does an operating system have to do with declaring and
initializing .... Oh, sorry, wrong MVS [*]. Carry on!

[*] As a result of early training, or imprinting, or something,
I have difficulty not interpreting these initials as the name of
an IBM mainframe operating system.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top