Microsoft Visual Studio

Discussion in 'C Programming' started by iC and iC++, Jun 1, 2010.

  1. iC and iC++

    iC and iC++ Guest

    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
     
    iC and iC++, Jun 1, 2010
    #1
    1. Advertising

  2. iC and iC++ wrote:
    > 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.

    --
     
    Alexander Bartolich, Jun 1, 2010
    #2
    1. Advertising

  3. iC and iC++

    iC and iC++ Guest

    On Jun 1, 2:21 pm, Alexander Bartolich <>
    wrote:
    > iC and iC++ wrote:
    > > 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.
    >
    > --

    its just an example... my point is MVS doesnt allow you to declare
    and initialize variables in one line.
     
    iC and iC++, Jun 1, 2010
    #3
  4. iC and iC++

    Rob Kendrick Guest

    On Tue, 1 Jun 2010 11:36:32 -0700 (PDT)
    "iC and iC++" <> wrote:

    > 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.
     
    Rob Kendrick, Jun 1, 2010
    #4
  5. "iC and iC++" <> writes:
    > On Jun 1, 2:21 pm, Alexander Bartolich <>
    > wrote:
    >> iC and iC++ wrote:
    >> > 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.
    >>

    > 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>

    --
    Keith Thompson (The_Other_Keith) <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"
     
    Keith Thompson, Jun 1, 2010
    #5
  6. "iC and iC++" <> writes:

    > On Jun 1, 2:21 pm, Alexander Bartolich <>
    > wrote:
    >> iC and iC++ wrote:
    >> > 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.
    >>

    > 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?

    --
    Ben.
     
    Ben Bacarisse, Jun 1, 2010
    #6
  7. iC and iC++

    iC and iC++ Guest

    On Jun 1, 4:35 pm, Richard Heathfield <> wrote:
    > Keith Thompson wrote:
    > > "iC and iC++" <> writes:

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

    >
    > > It almost certainly does.

    >
    > 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!
     
    iC and iC++, Jun 1, 2010
    #7
  8. iC and iC++

    iC and iC++ Guest

    On Jun 1, 3:50 pm, Keith Thompson <> wrote:
    > "iC and iC++" <> writes:
    >
    >
    >
    >
    >
    > > On Jun 1, 2:21 pm, Alexander Bartolich <>
    > > wrote:
    > >> iC and iC++ wrote:
    > >> > 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.

    >
    > >  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>
    >
    > --
    > Keith Thompson (The_Other_Keith)  <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.
     
    iC and iC++, Jun 1, 2010
    #8
  9. iC and iC++

    Ian Collins Guest

    On 06/ 2/10 10:10 AM, iC and iC++ wrote:
    > On Jun 1, 4:35 pm, Richard Heathfield<> wrote:
    >> Keith Thompson wrote:
    >>> "iC and iC++"<> writes:

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

    >>
    >>> It almost certainly does.

    >>
    >> s/almost //
    >>
    >> <snip>

    >
    > #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.

    --
    Ian Collins
     
    Ian Collins, Jun 1, 2010
    #9
  10. iC and iC++

    iC and iC++ Guest

    On Jun 1, 6:18 pm, Ian Collins <> wrote:
    > On 06/ 2/10 10:10 AM, iC and iC++ wrote:
    >
    >
    >
    >
    >
    > > On Jun 1, 4:35 pm, Richard Heathfield<>  wrote:
    > >> Keith Thompson wrote:
    > >>> "iC and iC++"<>  writes:

    >
    > >> <snip>

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

    >
    > >>> It almost certainly does.

    >
    > >> s/almost //

    >
    > >> <snip>

    >
    > > #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.
    >
    > --
    > Ian Collins


    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!
     
    iC and iC++, Jun 1, 2010
    #10
  11. iC and iC++

    Ian Collins Guest

    On 06/ 2/10 10:23 AM, iC and iC++ wrote:
    >> 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.

    --
    Ian Collins
     
    Ian Collins, Jun 1, 2010
    #11
  12. iC and iC++ wrote:
    > On Jun 1, 4:35 pm, Richard Heathfield<> wrote:
    >> Keith Thompson wrote:
    >>> "iC and iC++"<> writes:

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

    >>
    >>> It almost certainly does.

    >>
    >> 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;

    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
     
    James Lothian, Jun 1, 2010
    #12
  13. iC and iC++

    Default User Guest

    "iC and iC++" <> wrote in message
    news:...

    > So, MVS uses a c89 standard compiler?


    Yes. Microsoft has never really embraced C99, although some parts of it show
    up as extensions.



    Brian
     
    Default User, Jun 1, 2010
    #13
  14. iC and iC++

    iC and iC++ Guest

    On Jun 1, 7:51 pm, Richard Heathfield <> wrote:
    > James Lothian wrote:
    >
    > <snip>
    >
    > > 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.

    >
    > 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.
     
    iC and iC++, Jun 2, 2010
    #14
  15. Richard Heathfield wrote:
    > James Lothian wrote:
    >
    > <snip>
    >
    >> 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.

    >
    > 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
     
    James Lothian, Jun 2, 2010
    #15
  16. James Lothian wrote:
    > Richard Heathfield wrote:
    >> James Lothian wrote:
    >>
    >> <snip>
    >>
    >>> 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.

    >>
    >> 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

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

    James
     
    James Lothian, Jun 2, 2010
    #16
  17. iC and iC++

    iC and iC++ Guest

    On Jun 1, 8:04 pm, James Lothian
    <> wrote:
    > James Lothian wrote:
    > > Richard Heathfield wrote:
    > >> James Lothian wrote:

    >
    > >> <snip>

    >
    > >>> 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.

    >
    > >> 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

    >
    > 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..
     
    iC and iC++, Jun 2, 2010
    #17
  18. "iC and iC++" <> writes:
    > On Jun 1, 3:50 pm, Keith Thompson <> wrote:

    [...]
    >> 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.

    --
    Keith Thompson (The_Other_Keith) <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"
     
    Keith Thompson, Jun 2, 2010
    #18
  19. Geoff <> wrote:
    > "iC and iC++" wrote:
    > > int func(int x)
    > > {
    > >    //int y;
    > >    assert (x!=0);
    > >    int y = 4/x^2 + x/4;
    > >    return y;
    > > }

    <snip>
    > 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++.

    --
    Peter
     
    Peter Nilsson, Jun 2, 2010
    #19
  20. iC and iC++

    Guest

    In article <>,
    iC and iC++ <> wrote:
    > On Jun 1, 2:21 pm, Alexander Bartolich <>
    > wrote:
    > > iC and iC++ wrote:


    [ 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.

    --
    B. L. Massingill
    ObDisclaimer: I don't speak for my employers; they return the favor.
     
    , Jun 2, 2010
    #20
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. wh
    Replies:
    2
    Views:
    540
    Cowboy \(Gregory A. Beamer\)
    Jan 16, 2004
  2. Thirumalai
    Replies:
    0
    Views:
    691
    Thirumalai
    May 22, 2006
  3. rockdale
    Replies:
    1
    Views:
    626
    Juan T. Llibre
    Aug 23, 2006
  4. xman
    Replies:
    0
    Views:
    526
  5. vvj
    Replies:
    3
    Views:
    408
    Jerry Coffin
    Feb 16, 2007
Loading...

Share This Page