Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Damn you C language and all it's compilers!

Damn you C language and all it's compilers!

Scheduled Pinned Locked Moved The Lounge
c++phpvisual-studiocom
29 Posts 18 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L leppie

    Luca Leonardo Scorcia wrote:

    void die(void)

    Ahh, so that is why I see the 'explicit' void in the param list. I always though was just pedantic leftovers from the trigraph era ;P Now to go change all my declarations to have the proper intent. PS: How can you get the variables passed (eg the 1,2,3 in my example)? With va_args?

    xacc.ide
    IronScheme - 1.0 RC 1 - out now!
    ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition

    L Offline
    L Offline
    Lost User
    wrote on last edited by
    #7

    Er, erm, scrtathces head, cant remember, got sokm ecode of mine that does this, and uses va_start() and va_end() to pull them apart (or at least somehting like this). Its gotta be in ths SDK somewhere though!

    Morality is indistinguishable from social proscription

    L 1 Reply Last reply
    0
    • L Lost User

      Er, erm, scrtathces head, cant remember, got sokm ecode of mine that does this, and uses va_start() and va_end() to pull them apart (or at least somehting like this). Its gotta be in ths SDK somewhere though!

      Morality is indistinguishable from social proscription

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #8

      fat_boy wrote:

      Er, erm, scrtathces head, cant remember, got sokm ecode of mine that does this, and uses va_start() and va_end() to pull them apart (or at least somehting like this).

      Usage is a not problem. You use them anyways with ... parameters.

      xacc.ide
      IronScheme - 1.0 RC 1 - out now!
      ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition

      L 1 Reply Last reply
      0
      • L leppie

        The following compiles cleanly with no warnings:

        void die() {}

        int main()
        {
        die(1,2,3);
        }

        Does not work in C++ though. Why on earth would no C compiler (linker rather) (I tested MSVC and some embedded C compiler) emit a simple warning? X|

        xacc.ide
        IronScheme - 1.0 RC 1 - out now!
        ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition

        S Offline
        S Offline
        S Becker
        wrote on last edited by
        #9

        warning level -4 ?

        Regards Sascha

        L 1 Reply Last reply
        0
        • L leppie

          fat_boy wrote:

          Er, erm, scrtathces head, cant remember, got sokm ecode of mine that does this, and uses va_start() and va_end() to pull them apart (or at least somehting like this).

          Usage is a not problem. You use them anyways with ... parameters.

          xacc.ide
          IronScheme - 1.0 RC 1 - out now!
          ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #10

          Yeah, thats the most common way pf passing a load of junk around. The final handling func can use the va_xxx() funcs if you like, or you can pull the stack apart yourself if you like! (Or just want a bit of pain)

          Morality is indistinguishable from social proscription

          1 Reply Last reply
          0
          • S S Becker

            warning level -4 ?

            Regards Sascha

            L Offline
            L Offline
            leppie
            wrote on last edited by
            #11

            S. Becker wrote:

            warning level -4 ?

            There is no -4 option ;P But yeah, not even level 4 does it.

            xacc.ide
            IronScheme - 1.0 RC 1 - out now!
            ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition

            1 Reply Last reply
            0
            • L leppie

              Luca Leonardo Scorcia wrote:

              void die(void)

              Ahh, so that is why I see the 'explicit' void in the param list. I always though was just pedantic leftovers from the trigraph era ;P Now to go change all my declarations to have the proper intent. PS: How can you get the variables passed (eg the 1,2,3 in my example)? With va_args?

              xacc.ide
              IronScheme - 1.0 RC 1 - out now!
              ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition

              S Offline
              S Offline
              Stuart Dootson
              wrote on last edited by
              #12

              Well, actually, an empty parameter list is leftovers from when C didn't really do formal parameter lists and you declared functions as (if memory serves):

              int some_function()
              int param1;
              int param2;
              {
              do stuff
              }

              And trigraphs are still just about alive and well in the C++ standard currently out for ballot, I think you'll find ;-)

              Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p CodeProject MVP for 2010 - who'd'a thunk it!

              1 Reply Last reply
              0
              • L leppie

                VectorX wrote:

                Maybe die has been defined somewhere else?

                No, it does the same if it is called do_shit. Edit: I spy the word filter not doing it's job!

                xacc.ide
                IronScheme - 1.0 RC 1 - out now!
                ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition

                R Offline
                R Offline
                realJSOP
                wrote on last edited by
                #13

                Well there's your problem.

                .45 ACP - because shooting twice is just silly
                -----
                "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
                -----
                "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

                1 Reply Last reply
                0
                • L leppie

                  The following compiles cleanly with no warnings:

                  void die() {}

                  int main()
                  {
                  die(1,2,3);
                  }

                  Does not work in C++ though. Why on earth would no C compiler (linker rather) (I tested MSVC and some embedded C compiler) emit a simple warning? X|

                  xacc.ide
                  IronScheme - 1.0 RC 1 - out now!
                  ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition

                  P Offline
                  P Offline
                  PIEBALDconsult
                  wrote on last edited by
                  #14

                  HP C V7.3-009 on OpenVMS Alpha V8.3 says:

                  JB> cc CTEST.C

                  die(1,2,3);
                  

                  ....^
                  %CC-I-TOOMANYARGSO, In this statement, "die", which was declared with an old-style function definition, expects 0 arguments, but 3 a
                  re supplied.
                  at line number 5 in file MY$ROOT:[000000]CTEST.C;1

                  JB> cc CTEST.C /warning=verbose

                  die(1,2,3);
                  

                  ....^
                  %CC-I-TOOMANYARGSO, In this statement, "die", which was declared with an old-style function definition, expects 0 arguments, but 3 a
                  re supplied.
                  at line number 5 in file MY$ROOT:[000000]CTEST.C;1
                  Description: A function that was declared with an old-style function definition has been invoked with more arguments than it expects
                  . While this is valid C, it might not have been what you intended.
                  User Action: Make sure the number of arguments passed to a function match those specified in the function declaration. If the funct
                  ion is to be called with a variable number of arguments, it should use the facilities of <varargs.h> for old-style definitions. HP
                  generally recommends that old-style function definitions be replaced by prototype-format definitions, in which case variable argumen
                  t lists are specified using the ... notation and the definition uses the facilities of <stdarg.h>.

                  You owe HP an apology. :-D

                  1 Reply Last reply
                  0
                  • L leppie

                    The following compiles cleanly with no warnings:

                    void die() {}

                    int main()
                    {
                    die(1,2,3);
                    }

                    Does not work in C++ though. Why on earth would no C compiler (linker rather) (I tested MSVC and some embedded C compiler) emit a simple warning? X|

                    xacc.ide
                    IronScheme - 1.0 RC 1 - out now!
                    ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition

                    A Offline
                    A Offline
                    Anna Jayne Metcalfe
                    wrote on last edited by
                    #15

                    As others have said it's valid, but only for historical reasons. Use a construct like that and C will assume that you know what you're doing and leave you to it. Even if the compiler didn't warn you, lint will if you use it:

                    FlexeLint for C/C++ (Unix) Vers. 9.00d8, Copyright Gimpel Software 1985-2010
                    --- Module: offbyone.c (C)
                    1 void die() {}
                    2
                    3 int main()
                    4 {
                    _
                    5 die(1,2,3);
                    offbyone.c 5 Error 119: Too many arguments (3) for prototype 'die(void)'
                    offbyone.c 5 Warning 522: Highest operation, function 'die', lacks side-effects

                    You can try it yourself using Gimpel's online demonstrators for C[^] and C++[^]. :cool:

                    Anna :rose: Tech Blog | Visual Lint "Why would anyone prefer to wield a weapon that takes both hands at once, when they could use a lighter (and obviously superior) weapon that allows you to wield multiple ones at a time, and thus supports multi-paradigm carnage?"

                    L 1 Reply Last reply
                    0
                    • A Anna Jayne Metcalfe

                      As others have said it's valid, but only for historical reasons. Use a construct like that and C will assume that you know what you're doing and leave you to it. Even if the compiler didn't warn you, lint will if you use it:

                      FlexeLint for C/C++ (Unix) Vers. 9.00d8, Copyright Gimpel Software 1985-2010
                      --- Module: offbyone.c (C)
                      1 void die() {}
                      2
                      3 int main()
                      4 {
                      _
                      5 die(1,2,3);
                      offbyone.c 5 Error 119: Too many arguments (3) for prototype 'die(void)'
                      offbyone.c 5 Warning 522: Highest operation, function 'die', lacks side-effects

                      You can try it yourself using Gimpel's online demonstrators for C[^] and C++[^]. :cool:

                      Anna :rose: Tech Blog | Visual Lint "Why would anyone prefer to wield a weapon that takes both hands at once, when they could use a lighter (and obviously superior) weapon that allows you to wield multiple ones at a time, and thus supports multi-paradigm carnage?"

                      L Offline
                      L Offline
                      leppie
                      wrote on last edited by
                      #16

                      Thanks, will check it out :)

                      xacc.ide
                      IronScheme - 1.0 RC 1 - out now!
                      ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition

                      A 1 Reply Last reply
                      0
                      • L leppie

                        The following compiles cleanly with no warnings:

                        void die() {}

                        int main()
                        {
                        die(1,2,3);
                        }

                        Does not work in C++ though. Why on earth would no C compiler (linker rather) (I tested MSVC and some embedded C compiler) emit a simple warning? X|

                        xacc.ide
                        IronScheme - 1.0 RC 1 - out now!
                        ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition

                        U Offline
                        U Offline
                        User 4223959
                        wrote on last edited by
                        #17

                        g++ compiler considers it an error, not even a warning:

                        error: too many arguments to function `void MyNamespace::die()'

                        Run from NetBeans, via MinGW environment on Windows. Not sure about options: I use defaults.

                        L 1 Reply Last reply
                        0
                        • L leppie

                          Thanks, will check it out :)

                          xacc.ide
                          IronScheme - 1.0 RC 1 - out now!
                          ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition

                          A Offline
                          A Offline
                          Anna Jayne Metcalfe
                          wrote on last edited by
                          #18

                          Have fun. :) It's a very powerful too, although it does take a while to get the hang of using it effectively.

                          Anna :rose: Tech Blog | Visual Lint "Why would anyone prefer to wield a weapon that takes both hands at once, when they could use a lighter (and obviously superior) weapon that allows you to wield multiple ones at a time, and thus supports multi-paradigm carnage?"

                          L 1 Reply Last reply
                          0
                          • L leppie

                            The following compiles cleanly with no warnings:

                            void die() {}

                            int main()
                            {
                            die(1,2,3);
                            }

                            Does not work in C++ though. Why on earth would no C compiler (linker rather) (I tested MSVC and some embedded C compiler) emit a simple warning? X|

                            xacc.ide
                            IronScheme - 1.0 RC 1 - out now!
                            ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition

                            L Offline
                            L Offline
                            laniakea development
                            wrote on last edited by
                            #19

                            Hi! By default, if You write the prototype without any parameters in parenthesis, as in: void die() {}, then C compiler assumes that is such a function You can pass ANY number (of any type) of parameters; If You wish to have a function which will NOT receive any parameter, then, You have to write void die(void){}; (mark the word VOID in the function's parameter list) When C++ or Java is in the concern, then, the empty parenthesis mean that this is the function which does NOT accept the parameters in list; In C++ You can set void in parenthesis, but it is not mandatory. Best regards!

                            I 1 Reply Last reply
                            0
                            • U User 4223959

                              g++ compiler considers it an error, not even a warning:

                              error: too many arguments to function `void MyNamespace::die()'

                              Run from NetBeans, via MinGW environment on Windows. Not sure about options: I use defaults.

                              L Offline
                              L Offline
                              leppie
                              wrote on last edited by
                              #20

                              We have covered the fact that it wont compile as C++. Call gcc directly.

                              xacc.ide
                              IronScheme - 1.0 RC 1 - out now!
                              ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition

                              U 1 Reply Last reply
                              0
                              • A Anna Jayne Metcalfe

                                Have fun. :) It's a very powerful too, although it does take a while to get the hang of using it effectively.

                                Anna :rose: Tech Blog | Visual Lint "Why would anyone prefer to wield a weapon that takes both hands at once, when they could use a lighter (and obviously superior) weapon that allows you to wield multiple ones at a time, and thus supports multi-paradigm carnage?"

                                L Offline
                                L Offline
                                leppie
                                wrote on last edited by
                                #21

                                Pity the site is timing out when trying to load it (tried the home page too). Will try again tonite from a different internet.

                                xacc.ide
                                IronScheme - 1.0 RC 1 - out now!
                                ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition

                                A M 2 Replies Last reply
                                0
                                • L leppie

                                  Pity the site is timing out when trying to load it (tried the home page too). Will try again tonite from a different internet.

                                  xacc.ide
                                  IronScheme - 1.0 RC 1 - out now!
                                  ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition

                                  A Offline
                                  A Offline
                                  Anna Jayne Metcalfe
                                  wrote on last edited by
                                  #22

                                  It must be the CP effect. :doh:

                                  Anna :rose: Tech Blog | Visual Lint "Why would anyone prefer to wield a weapon that takes both hands at once, when they could use a lighter (and obviously superior) weapon that allows you to wield multiple ones at a time, and thus supports multi-paradigm carnage?"

                                  1 Reply Last reply
                                  0
                                  • L leppie

                                    We have covered the fact that it wont compile as C++. Call gcc directly.

                                    xacc.ide
                                    IronScheme - 1.0 RC 1 - out now!
                                    ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition

                                    U Offline
                                    U Offline
                                    User 4223959
                                    wrote on last edited by
                                    #23

                                    leppie wrote:

                                    Call gcc directly

                                    I just did - you are right; it gives no warnings. Sorry for misplaced post :sigh:

                                    1 Reply Last reply
                                    0
                                    • L laniakea development

                                      Hi! By default, if You write the prototype without any parameters in parenthesis, as in: void die() {}, then C compiler assumes that is such a function You can pass ANY number (of any type) of parameters; If You wish to have a function which will NOT receive any parameter, then, You have to write void die(void){}; (mark the word VOID in the function's parameter list) When C++ or Java is in the concern, then, the empty parenthesis mean that this is the function which does NOT accept the parameters in list; In C++ You can set void in parenthesis, but it is not mandatory. Best regards!

                                      I Offline
                                      I Offline
                                      ian__lindsay 0
                                      wrote on last edited by
                                      #24

                                      I would say that it is because in C, no parameter type ends up being interpreted as just an int passed in (same as if you don't specify a return type). Add in the comma operator which if memory serves correctly does something like execute each expression and return the value of the last one, and you have compiling code. So what ends up happening is something like void die(int a) { } die(3);

                                      1 Reply Last reply
                                      0
                                      • L leppie

                                        Pity the site is timing out when trying to load it (tried the home page too). Will try again tonite from a different internet.

                                        xacc.ide
                                        IronScheme - 1.0 RC 1 - out now!
                                        ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition

                                        M Offline
                                        M Offline
                                        Malmberg
                                        wrote on last edited by
                                        #25

                                        leppie wrote:

                                        Will try again tonite from a different internet.

                                        I find it very hard to let that sentence pass uncommented. In fact, I failed to. ;P

                                        1 Reply Last reply
                                        0
                                        • L leppie

                                          The following compiles cleanly with no warnings:

                                          void die() {}

                                          int main()
                                          {
                                          die(1,2,3);
                                          }

                                          Does not work in C++ though. Why on earth would no C compiler (linker rather) (I tested MSVC and some embedded C compiler) emit a simple warning? X|

                                          xacc.ide
                                          IronScheme - 1.0 RC 1 - out now!
                                          ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition

                                          C Offline
                                          C Offline
                                          CDMTJX
                                          wrote on last edited by
                                          #26

                                          Wild guess its related to C++ haveing overloading and it can't make a match between die with no args, and die with 3. C doesn't have overloading, so you must mean the only die declared, even if its wrong. I'm amused Alpha C gives a warning; I knew several people who worked on it... 8-)

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups