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

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

                        F Offline
                        F Offline
                        fglenn
                        wrote on last edited by
                        #27

                        I wish I could remember who said this: C will allow you to shoot yourself in the foot. C++ makes it harder, but if you succeed, it will take off your whole leg. :-D

                        Fletcher Glenn

                        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

                          D Offline
                          D Offline
                          dennislx
                          wrote on last edited by
                          #28

                          If you are writing like this in c/c++ maybe you should look for other language to use, and leave it to real programmers?

                          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

                            K Offline
                            K Offline
                            Kenneth Kasajian
                            wrote on last edited by
                            #29

                            I agree. It's part of the language to allow that, but there should be a way to enable a warning for that. One thing that I've done successfully with C code is that I created a separate .cpp file that simply #included the corresponding .C file. That way, the .C file stayed as it is, and can be used by other tools, platform builds, etc., but on my computer, I would use a C++ compiler to build the C code so that I can get a lot more warnings, etc. In fact, I've found that to be the best way to compile C code into .NET C++/CLI, without changing the original .C file and project. That way, the C++/CLI version of the code can be easily tested using .NET unit testing tools -- but I digress.

                            ken@kasajian.com / www.kasajian.com

                            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