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. General Programming
  3. C / C++ / MFC
  4. const void as return type

const void as return type

Scheduled Pinned Locked Moved C / C++ / MFC
question
6 Posts 3 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.
  • C Offline
    C Offline
    crewchill
    wrote on last edited by
    #1

    I found this code a little confusing. Due to proprietary nature of the original source, I have to abstract this out. What does const void return value mean? I can understand the intent of "const void*" return value, but "const void" seems to be just a typo? Am I missing anything fancy with the construct here?

    #include typedef const void (*hello)();

    const void x()
    {
    printf("x() is called\n");
    }

    int main()
    {
    hello test=x;
    test();
    }

    S L 2 Replies Last reply
    0
    • C crewchill

      I found this code a little confusing. Due to proprietary nature of the original source, I have to abstract this out. What does const void return value mean? I can understand the intent of "const void*" return value, but "const void" seems to be just a typo? Am I missing anything fancy with the construct here?

      #include typedef const void (*hello)();

      const void x()
      {
      printf("x() is called\n");
      }

      int main()
      {
      hello test=x;
      test();
      }

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

      I don't believe you're missing anything - it does seem odd. In fact, gcc raises a warning on a function returning const void:

      a.c:2: warning: function definition has qualified void return type

      Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

      C 1 Reply Last reply
      0
      • C crewchill

        I found this code a little confusing. Due to proprietary nature of the original source, I have to abstract this out. What does const void return value mean? I can understand the intent of "const void*" return value, but "const void" seems to be just a typo? Am I missing anything fancy with the construct here?

        #include typedef const void (*hello)();

        const void x()
        {
        printf("x() is called\n");
        }

        int main()
        {
        hello test=x;
        test();
        }

        L Offline
        L Offline
        led mike
        wrote on last edited by
        #3

        crewchill wrote:

        I found this code a little confusing.

        Yes. Working with legacy code I often find confusing items or constructs. My initial reaction is, like yours:

        crewchill wrote:

        Am I missing anything fancy with the construct here?

        Then later it becomes apparent that the author was just stupid. :sigh: On the bright side, tomorrow is FRIDAY! :beer: :jig:

        C 1 Reply Last reply
        0
        • S Stuart Dootson

          I don't believe you're missing anything - it does seem odd. In fact, gcc raises a warning on a function returning const void:

          a.c:2: warning: function definition has qualified void return type

          Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

          C Offline
          C Offline
          crewchill
          wrote on last edited by
          #4

          Hm... which gcc are you using? Mine doesn't even complain about it.

          ~
          $ cat x.c
          #include <stdio.h>

          typedef const void (*hello)();

          const void x()
          {
          printf("x() is called\n");
          }

          int main()
          {
          hello test=x;
          test();
          }

          ~
          $ gcc x.c

          ~
          $ ./a.exe
          x() is called

          ~
          $ gcc --ver
          Reading specs from /usr/lib/gcc/i686-pc-cygwin/3.4.4/specs
          Configured with: /usr/build/package/orig/test.respin/gcc-3.4.4-3/configure --ver
          bose --prefix=/usr --exec-prefix=/usr --sysconfdir=/etc --libdir=/usr/lib --libe
          xecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --enable-langu
          ages=c,ada,c++,d,f77,pascal,java,objc --enable-nls --without-included-gettext --
          enable-version-specific-runtime-libs --without-x --enable-libgcj --disable-java-
          awt --with-system-zlib --enable-interpreter --disable-libgcj-debug --enable-thre
          ads=posix --enable-java-gc=boehm --disable-win32-registry --enable-sjlj-exceptio
          ns --enable-hash-synchronization --enable-libstdcxx-debug
          Thread model: posix
          gcc version 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)

          S 1 Reply Last reply
          0
          • L led mike

            crewchill wrote:

            I found this code a little confusing.

            Yes. Working with legacy code I often find confusing items or constructs. My initial reaction is, like yours:

            crewchill wrote:

            Am I missing anything fancy with the construct here?

            Then later it becomes apparent that the author was just stupid. :sigh: On the bright side, tomorrow is FRIDAY! :beer: :jig:

            C Offline
            C Offline
            crewchill
            wrote on last edited by
            #5

            Amen to Friday. My head is about to explode already. You know the scariest part was, this is quite recent code. The older version didn't have this and somehow the extra "const" appeared after it's being code reviewed :( Not by me, mind you.

            1 Reply Last reply
            0
            • C crewchill

              Hm... which gcc are you using? Mine doesn't even complain about it.

              ~
              $ cat x.c
              #include <stdio.h>

              typedef const void (*hello)();

              const void x()
              {
              printf("x() is called\n");
              }

              int main()
              {
              hello test=x;
              test();
              }

              ~
              $ gcc x.c

              ~
              $ ./a.exe
              x() is called

              ~
              $ gcc --ver
              Reading specs from /usr/lib/gcc/i686-pc-cygwin/3.4.4/specs
              Configured with: /usr/build/package/orig/test.respin/gcc-3.4.4-3/configure --ver
              bose --prefix=/usr --exec-prefix=/usr --sysconfdir=/etc --libdir=/usr/lib --libe
              xecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --enable-langu
              ages=c,ada,c++,d,f77,pascal,java,objc --enable-nls --without-included-gettext --
              enable-version-specific-runtime-libs --without-x --enable-libgcj --disable-java-
              awt --with-system-zlib --enable-interpreter --disable-libgcj-debug --enable-thre
              ads=posix --enable-java-gc=boehm --disable-win32-registry --enable-sjlj-exceptio
              ns --enable-hash-synchronization --enable-libstdcxx-debug
              Thread model: posix
              gcc version 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)

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

              i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1 (Apple Inc. build 5490)

              Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

              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