const void as return type
-
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();
} -
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();
}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
-
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();
}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:
-
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
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) -
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:
-
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)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