473,397 Members | 2,116 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

void parameter argument

Dan
Is it just me, or is the removal of support for the word "void" in a
parameter list extremely annoying? Some of us have been programming for
years putting "void function_name (void)" - and it really doesn't feel nice
having to miss it out. Is there any reason for them removing this? I don't
suppose there's a pragma or something to stop the compiler barking about it
is there?
Nov 17 '05 #1
14 6674
AFAIK, the syntax

void function_name(void)

was introduced in ANSI C (or perhaps earlier) because the old, original
K&R C allowed function prototypes with "unspecified" arguments. So, in
C you could also say,

void function_name()

which did _not_ mean "this function does not take any arguments," but
rather "I'm not telling you what arguments this function takes, if
any." So, the "(void)" syntax was a necessary addition to distinguish
between this non-disclosure and a declaration that a function took no
arguments. It was a backward compatibility thing.

I suppose that it was left out in C# because it's superfluous. In a
language that requires you to declare all arguments, there's no need to
distinguish between the two cases with a keyword "void".

Nov 17 '05 #2
Dan wrote:
Is it just me, or is the removal of support for the word "void" in a
parameter list extremely annoying? Some of us have been programming for
years putting "void function_name (void)" - and it really doesn't feel nice
having to miss it out. Is there any reason for them removing this? I don't
suppose there's a pragma or something to stop the compiler barking about it
is there?


But you have to type less, so what's the big deal? ;). Just get used to
() means (nothing) or (void) or (nada) and you're done :)

FB

--
------------------------------------------------------------------------
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
Nov 17 '05 #3
Dan
> > Is it just me, or is the removal of support for the word "void" in a
parameter list extremely annoying? Some of us have been programming for
years putting "void function_name (void)" - and it really doesn't feel nice having to miss it out. Is there any reason for them removing this? I don't suppose there's a pragma or something to stop the compiler barking about it is there?


But you have to type less, so what's the big deal? ;). Just get used to
() means (nothing) or (void) or (nada) and you're done :)

Unfortunately, at work it's part of our coding standard that you have to put
"void" in a function without parameters (we use C at work). So I can't get
used to not using it.
Nov 17 '05 #4
Dan
> > Is it just me, or is the removal of support for the word "void" in a
parameter list extremely annoying? Some of us have been programming for
years putting "void function_name (void)" - and it really doesn't feel nice having to miss it out. Is there any reason for them removing this? I don't suppose there's a pragma or something to stop the compiler barking about it is there?


But you have to type less, so what's the big deal? ;). Just get used to
() means (nothing) or (void) or (nada) and you're done :)

Unfortunately, at work it's part of our coding standard that you have to put
"void" in a function without parameters (we use C at work). So I can't get
used to not using it.
Nov 17 '05 #5
But now you're using C#. You have to accept that C# is not C and adapt to
new paradigms. void for empty argument lists always has been rubbish because
void foo() and void foo(void) are one and the same.

"Dan" <da*@nospam.com> schrieb im Newsbeitrag
news:e$**************@TK2MSFTNGP09.phx.gbl...
Is it just me, or is the removal of support for the word "void" in a
parameter list extremely annoying? Some of us have been programming for years putting "void function_name (void)" - and it really doesn't feel nice having to miss it out. Is there any reason for them removing this? I don't suppose there's a pragma or something to stop the compiler barking
about
it is there?
But you have to type less, so what's the big deal? ;). Just get used to
() means (nothing) or (void) or (nada) and you're done :)

Unfortunately, at work it's part of our coding standard that you have to

put "void" in a function without parameters (we use C at work). So I can't get used to not using it.

Nov 17 '05 #6
Dan
I'm only using C# at home - so I can't get un-used to using void. I don't
see why your example makes it rubbish.

Never mind though - I was hoping someone you reply saying - "yeah, just use
this pragma, and the compiler won't bark".

But now you're using C#. You have to accept that C# is not C and adapt to
new paradigms. void for empty argument lists always has been rubbish because void foo() and void foo(void) are one and the same.

"Dan" <da*@nospam.com> schrieb im Newsbeitrag
news:e$**************@TK2MSFTNGP09.phx.gbl...
> Is it just me, or is the removal of support for the word "void" in a
> parameter list extremely annoying? Some of us have been programming for > years putting "void function_name (void)" - and it really doesn't feel
nice
> having to miss it out. Is there any reason for them removing this?
I don't
> suppose there's a pragma or something to stop the compiler barking

about
it
> is there?

But you have to type less, so what's the big deal? ;). Just get used

to () means (nothing) or (void) or (nada) and you're done :)

Unfortunately, at work it's part of our coding standard that you have to

put
"void" in a function without parameters (we use C at work). So I can't

get
used to not using it.


Nov 17 '05 #7
When using C# instead of C you have to get used to a lot of things.
for example:

byte a=1
byte b=2;
byte c = a+b; // error cannot convert int to byte

float f = 1.0; // cannot convert double to float
"Dan" <da*@nospam.com> schrieb im Newsbeitrag
news:d3*******************@news.demon.co.uk...
I'm only using C# at home - so I can't get un-used to using void. I don't
see why your example makes it rubbish.

Never mind though - I was hoping someone you reply saying - "yeah, just use this pragma, and the compiler won't bark".

But now you're using C#. You have to accept that C# is not C and adapt to
new paradigms. void for empty argument lists always has been rubbish because
void foo() and void foo(void) are one and the same.

"Dan" <da*@nospam.com> schrieb im Newsbeitrag
news:e$**************@TK2MSFTNGP09.phx.gbl...
> > Is it just me, or is the removal of support for the word "void" in a > > parameter list extremely annoying? Some of us have been
programming for
> > years putting "void function_name (void)" - and it really doesn't feel nice
> > having to miss it out. Is there any reason for them removing
this? I don't
> > suppose there's a pragma or something to stop the compiler barking

about
it
> > is there?
>
> But you have to type less, so what's the big deal? ;). Just get used to > () means (nothing) or (void) or (nada) and you're done :)
Unfortunately, at work it's part of our coding standard that you have

to put
"void" in a function without parameters (we use C at work). So I
can't get
used to not using it.



Nov 17 '05 #8
Dan
> byte a=1
byte b=2;
byte c = a+b; // error cannot convert int to byte
I didn't know that one. That's a bit crap really - where's the int come
from?

float f = 1.0; // cannot convert double to float


I don't mind that one - I always put 1.0f in my code.
Nov 17 '05 #9
"Dan" <da*@nospam.com> schrieb im Newsbeitrag
news:d3*******************@news.demon.co.uk...
byte a=1
byte b=2;
byte c = a+b; // error cannot convert int to byte


I didn't know that one. That's a bit crap really - where's the int come
from?

Every signed integral calculation is automatically propagated to an int in
C# (except expressions with type long), don't ask me why as I've never
understood this one.
In C it was a bit different, the result of the expression was always the
biggest type of the operands so byte+short yields to short. But if you
assigned it back to an byte there was no error since all types were
automatically converted without warning so it could happen that you lose a
value.
float f = 1.0; // cannot convert double to float


I don't mind that one - I always put 1.0f in my code.

Yes but the problem is that every method or constant of the math class
returns double so you always have to cast almost every line of code
especially when using APIs like direct3d which only operates with float.
Nov 17 '05 #10
Dan
> > > byte a=1
byte b=2;
byte c = a+b; // error cannot convert int to byte


I didn't know that one. That's a bit crap really - where's the int come
from?

Every signed integral calculation is automatically propagated to an int in
C# (except expressions with type long), don't ask me why as I've never
understood this one.
In C it was a bit different, the result of the expression was always the
biggest type of the operands so byte+short yields to short. But if you
assigned it back to an byte there was no error since all types were
automatically converted without warning so it could happen that you lose a
value.
float f = 1.0; // cannot convert double to float


I don't mind that one - I always put 1.0f in my code.

Yes but the problem is that every method or constant of the math class
returns double so you always have to cast almost every line of code
especially when using APIs like direct3d which only operates with float.

I see what you mean - that could be a major pain in the arse. I'm soon to
find out though, as I'm now starting work on a big project at home in C#.
It seems very good so far - but it's mostly just UI stuff that I've been
setting up so far, so I've not been doing much with floats or doubles yet.

As for using DirectX in C# - wouldn't that be very slow? I use DirectX at
work (I'm a games engine programmer). From what I've read so far about C# -
it's not very good for performance intensive applications. Is this right?

Nov 17 '05 #11
"cody" <de********@gmx.de> wrote in message
news:es**************@TK2MSFTNGP14.phx.gbl...
void for empty argument lists always has been rubbish because
void foo() and void foo(void) are one and the same.


foo() & foo(void) have never meant the same thing:

In C & C++
foo() takes an unknown number of parameters (of unknown type)
foo(void) takes no parameters

In C#
foo() takes no parameters
foo(void) is a syntax error.
Nov 17 '05 #12
> As for using DirectX in C# - wouldn't that be very slow? I use DirectX at
work (I'm a games engine programmer). From what I've read so far about C# - it's not very good for performance intensive applications. Is this right?


In my experience Managed DirectX's performance is not bad, officially they
say it is 80% of the performance of native DirectX. If you don't create to
many new objects during the gameloop (which normally isn't necessary) you
won't notice GC.
There is a Quake 2 implementation with .NET in the Internet which runs faily
good.
Also JIT & GC algorithms getting better and better I'll expect that in some
time more games will be developed using .NET or Java.
Nov 17 '05 #13
void for empty arguments lists is a necessity in C for the reasons I
outlined last night: an empty argument list in C does _not_ mean that
there are no arguments. It means that the argument list is unspecified.
It could be empty, or it could take 15 arguments. Empty parentheses in
C mean that you're "not saying." So, the (void) notation is necessary
in order to say that you _are_ specifying what arguments the function
takes, and there _aren't any_.

Dan, you have to look at it from a semantic point of view, not a
syntactic one. Semantically, your workplace standard is correct: you
have to say (void) in order to tell the C compiler that the function
takes no arguments. However, it's a syntactic hack that was introduced
into C because some nitwit in the early days of C thought that
"unspecified parameters" function declarations were the way to go.

There's no need to introduce such a hack into C#. C# is starting with a
clean slate, so it uses the logical notation for methods that take no
parameters: empty parentheses. The problem is not that C# has
introduced a strange notation to the language. The problem is that C
introduced an ugly hack decades ago to get around a bad language design
decision.

Nov 17 '05 #14
Dan <da*@nospam.com> wrote:
Unfortunately, at work it's part of our coding standard that you have to put
"void" in a function without parameters (we use C at work). So I can't get
used to not using it.


You'll *have* to get used to C not being the same as C# in many ways.
At the same time, you should get used to following the normal C# naming
conventions - PascalCasedMethodNames etc.

Trying to write C# while pretending it's C is a bad way to learn C#.
Treat it as if it were a completely different language as far as you
can.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

52
by: Vladimir Grul | last post by:
Hello, I have a class member function declared as class some_class { .... virtual int call(void); }; Can I use this-> inside the function body?
5
by: Manuel Maria Diaz Gomez | last post by:
Thanks Victor for your previous answer! I have the following problem: I would like to implement an interface class that defines a pure virtual method that could take any parameter as input, ...
13
by: PengYu.UT | last post by:
Hi, I know that there is a difference (in C) between int fun(void); int fun(); The first one takes no arguments. The second can take any number of arguments, including 0.
4
by: Mark Antony | last post by:
Hello everyone, I am writing a function that takes a void* as an argument. In this function, there is some data that needs to be given back in the form of a void pointer. This is the simple test...
3
by: john | last post by:
Hello: I have a simple program with a function that takes a void * parameter. I want to be able to distinguish a type once the flow of control is inside the body of the funtion. I am using...
8
by: John Hanley | last post by:
I working in C. I haven't paid much attention to void pointers in the past, but I am wondering if I can use them for my various linked lists to save work. I have two different linked lists that...
6
by: bob_jenkins | last post by:
{ const void *p; (void)memset((void *)p, ' ', (size_t)10); } Should this call to memset() be legal? Memset is of type void *memset(void *, unsigned char, size_t) Also, (void *) is the...
9
by: Juggernaut | last post by:
I am trying to create a p_thread pthread_create(&threads, &attr, Teste, (void *)var); where var is a char variable. But this doesnt't work, I get this message: test.c:58: warning: cast to pointer...
2
by: Barry | last post by:
The problem brought by one earlier post from comp.lang.c++ http://groups.google.com/group/comp.lang.c++/browse_thread/thread/bf636c48b84957b/ I take part of the question and reproduce the code to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.