Re: void and this

From: David B. Held (dheld_at_codelogicconsulting.com)
Date: 10/07/03


Date: Tue, 7 Oct 2003 01:43:25 -0500


"Kevin Goodsell" <usenet1.spamfree.fusion@neverbox.com> wrote in message
news:H7sgb.1128$dn6.28@newsread4.news.pas.earthlink.net...
> David B. Held wrote:
> >
> > I understand the distinction and the history, but I still fail to
> > understand why (void) is frowned upon or viewed as "C".
> > I happen to like the explicit way in which it says "this function
> > takes no arguments".
>
> Well, I don't mean to be argumentative,

Don't apologize for disagreeing!

> but it seems to me that showing the function with no
> arguments is possibly a *more* explicit (or at least logical)
> way of showing that it takes no arguments than showing it
> with what appears to be a void argument. Granted, no C++
> programmer will actually be lead to believe that the function
> takes one argument of type void, but that is what the syntax
> suggests. This is why I agree that the syntax is an
> "abomination", as was stated elsewhere.
> [...]

Well, void doesn't quite work with metaprogramming, but it
should. I mean, how handy would it be if we could substitute
any number of void arguments in a template function? We
wouldn't need to write a hundred overloads! Like this:

int foo(void, void); // takes no arguments

Why would you want to do that? Why, so you could do this,
of course:

template <typename T1 = void, typename T2 = void, ...>
int foo(T1 t1, T2 t2, ...);

And voila! You just wrote N overloads that currently require
tedious cut-n-paste or preprocessor magic.

Anyway, I think of "void" as a "metanull". It's a metavalue
which indicates nothingness, like NULL, kinda. Would you
say that this is more "explicit"?

int* p = ;

Believe it or not, I see "int foo()" in a similar way, which
rubs me the wrong way just as the statement above
undoubtedly rubs most people.

Dave

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.521 / Virus Database: 319 - Release Date: 9/23/2003


Relevant Pages

  • Re: void and this
    ... You use type traits to see if an argument is void or not. ... int foo; ... you could do c'tor forwarding very nicely: ... because it's too tedious to write the overloads. ...
    (comp.lang.cpp)
  • Help in Java swings(internal Frame)
    ... public int getSize() ... public void valueChanged{ ... private JScrollPane scrollPane1; ... public class PeakContainer extends JInternalFrame ...
    (comp.lang.java.programmer)
  • [PATCH] get rid if __cpuinit and __cpuexit
    ... unsigned long action, void *hcpu) ... unsigned int cpu = hcpu; ... -static int __cpuinit ... __cpu_up(unsigned int cpu) ...
    (Linux-Kernel)
  • [PATCH,RFC 2.6.14 09/15] KGDB: SuperH-specific changes
    ... This adds basic support for KGDB on SuperH as well as adding some architecture ... -static int kgdb_uart_getchar ... -static void kgdb_uart_putchar ... * The command-line option can include a serial port specification ...
    (Linux-Kernel)
  • problem in java swings
    ... public int getSize() ... public void valueChanged{ ... private JScrollPane scrollPane1; ... public class PeakContainer extends JInternalFrame ...
    (comp.lang.java.programmer)