473,890 Members | 1,350 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using "return" with parantheses?

Hi,

I'm a game developer programming mostly in C and ASM for about 7 years.

Today at work a colleague (a C++ programmer) yelled at me I'm a bad C
programmer because I use "return(0); " instead of "return 0;".
He explained that "return" is not a function but a stament, like I
didn't know already. The other colleagues also argreed with him :(.

Can someone please explain what's so wrong about using "return" with
parantheses? I've used them like that from the beginning.

Thank you,
Mike Machuidel

Nov 13 '05
32 8923
Mike Machuidel wrote:
Today, at work, a colleague (a C++ programmer) yelled at me.
I'm a bad C programmer
because I use "return(0); " instead of "return 0;".
He explained that "return" is not a function but a statment,
like I didn't know already.
The other colleagues also agreed with him :(.

Can someone please explain
what's so wrong about using "return" with parentheses?
I've used them like that from the beginning.
cat main.c #define return(value) return value

int main(int argc, char* argv[]) {
return(0);
}
gcc -Wall -std=c99 -pedantic -E main.c

# 1 "main.c"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "main.c"
int main(int argc, char* argv[]) {
return 0;
}

Nov 13 '05 #11

"Mike Machuidel" <ma*******@yaho o.com> wrote in message
news:3f******** *************** @news.xs4all.nl ...
Hi,

I'm a game developer programming mostly in C and ASM for about 7 years.

Today at work a colleague (a C++ programmer) yelled at me I'm a bad C
programmer because I use "return(0); " instead of "return 0;".
He explained that "return" is not a function but a stament, like I
didn't know already. The other colleagues also argreed with him :(.

Can someone please explain what's so wrong about using "return" with
parantheses? I've used them like that from the beginning.


I sometimes use them. One reason might be that I used to use PL/I, where
they are required for return statements returning a value.

The syntax of if, for, and while, to name a few, C statements, requires
parenthesis and I don't think it makes them look like functions.

In any case, I think putting the return value on the return statement is
better than the traditional Fortran method of assigning to a variable named
after the function. (Though for Fortran implementations with the ENTRY
statement, assigning to a variable is probably better, because of
type/conversion problems.)

-- glen
Nov 13 '05 #12
"James Antill" <ja***********@ and.org> wrote in message
news:pa******** *************** *****@and.org.. .
...parentheses are mainly about style, and yes examples can be provided at
either extreme that are terrible.

[...]

Style is a touchy subject because the language rules only provide a starting
ground. I personally hate seeing code with the opening { on the same line
as the if statement, while loops, etc...However, I do like them to be on the
same line as a do and with the while on the same lines as the closing }, for
some reason (don't ask me why, I don't know; I just like it that way). I
don't want to get into an argument over who is right because who's to say I
am? I like how I write my code and that's the reason I do it thay way.
I've also never had a complaint about my style. I just hope that the
company I work for doesn't decide to make any style changes while I'm still
around.

Sean

Nov 13 '05 #13
"Fao, Sean" <en**********@y ahoo.comI-WANT-NO-SPAM> writes:
[...]
When I first started programming in C, I was asked to write a macro, which
would calculate the number of elements in an array, but couldn't use any
functions. I knew I could do it like this:

#define NUM_ELTS(x) (sizeof(x) / sizeof(x[0]))

However, at the time, the parentheses that I was taught to use made me think
that sizeof was a function.


I would write that as

#define NUM_ELTS(x) (sizeof(x) / sizeof((x)[0]))

References to macro arguments should always be enclosed in
parentheses; otherwise you can run into some really nasty problems
with operator precedence. Remember that the argument is expanded into
the text, not into the expression tree.

This rule applies to function-like macros whose arguments are
expressions; it may not apply to more bizarre macro definitions.

#include <stdio.h>

#define SIX 1+5
#define NINE 8+1

int main(void)
{
printf("%d * %d = %d\n", SIX, NINE, SIX * NINE);
return 0;
}

--
Keith Thompson (The_Other_Keit h) ks*@cts.com <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
Nov 13 '05 #14
On Fri, 24 Oct 2003 12:43:05 +0200, in comp.lang.c , Mike Machuidel
<ma*******@yaho o.com> wrote:
Hi,

Can someone please explain what's so wrong about using "return" with
parantheses?


There's nothing wrong, they're just not needed. For not particular
reason I tend to use them if the return is a messy expression,
otherwise not.
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.c om/ms3/bchambless0/welcome_to_clc. html>
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 13 '05 #15
"E. Robert Tisdale" <E.************ **@jpl.nasa.gov > wrote in
news:3F******** ******@jpl.nasa .gov on Fri 24 Oct 2003 02:28:09p:
> cat main.c

#define return(value) return value

int main(int argc, char* argv[]) {
return(0);
}
> gcc -Wall -std=c99 -pedantic -E main.c

# 1 "main.c"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "main.c"
int main(int argc, char* argv[]) {
return 0;
}


Eh, but if you have to run your code through the pre-processor to make it
conform to your company's standards, you'll probably find yourself on the
short end of the chewed-out stick. After all, at least on my system,
running the pre-processor on any of my code produces something that's full
of odd magic numbers and rather ugly lines of stuff I didn't write.

So, what does your code really prove? We all know the pre-processor phase
comes before the compilation phase.

Nov 13 '05 #16
"August Derleth" <li************ *****@onewest.n et> wrote in message
news:Xn******** *************** ***********@63. 223.8.240...
"E. Robert Tisdale" <E.************ **@jpl.nasa.gov > wrote in
news:3F******** ******@jpl.nasa .gov on Fri 24 Oct 2003 02:28:09p:
> cat main.c

#define return(value) return value

int main(int argc, char* argv[]) {
return(0);
}
> gcc -Wall -std=c99 -pedantic -E main.c

# 1 "main.c"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "main.c"
int main(int argc, char* argv[]) {
return 0;
}


Eh, but if you have to run your code through the pre-processor to make it
conform to your company's standards, you'll probably find yourself on the
short end of the chewed-out stick. After all, at least on my system,
running the pre-processor on any of my code produces something that's full
of odd magic numbers and rather ugly lines of stuff I didn't write.

So, what does your code really prove? We all know the pre-processor phase
comes before the compilation phase.

You are right in your statements, but wrong in reasoning. We all
know that preprocessing phase comes *after* reviewing phase ;-)
It's about human readers of code, compiler doesn't care about
parentheses in this particular case, and proposed "solution" only
adds more useless clutter into code.

OTOH, I've seen ([sur]real code in [sur]real system) something like:

#define return(x) \
{ \
printf("%d\n", x); \
/* 10 or so lines of "debugging" code */
return 0; \
}

In order to use this "facility", return *had* to be coded with parentheses
around value. If that was a good practice is beside the point on hand.
Nov 13 '05 #17
Fao, Sean <en**********@y ahoo.comi-want-no-spam> scribbled the following:
In my opinion, any C programmer who doesn't know that parentheses are
optional in these cases, and others, has no business working on any real
projects other then the ones out of a workbook. Maybe your use of
parentheses suggested to you coworkers a lack of understanding. As you
pointed out, it's not wrong; but, they aren't necessary. What would you
think if a coworker started writing code like this: int main(void)
{
int a = (32);
printf("%d\n", (a));
return (0);
}


Your printf statement has too few parantheses. It's much more legible
as:

(printf)(("%d\n "), (a));

--
/-- Joona Palaste (pa*****@cc.hel sinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
Nov 13 '05 #18
August Derleth wrote:
"E. Robert Tisdale" <E.************ **@jpl.nasa.gov > wrote
> cat main.c
.... snip ...
So, what does your code really prove? We all know the
pre-processor phase comes before the compilation phase.


It proves him to be a troll. If we all ignore him, apart from
correcting the persistent errors, maybe he will go away.

--
Chuck F (cb********@yah oo.com) (cb********@wor ldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net> USE worldnet address!
Nov 13 '05 #19
"Joona I Palaste" <pa*****@cc.hel sinki.fi> wrote in message
news:bn******** **@oravannahka. helsinki.fi...
Your printf statement has too few parantheses. It's much more legible
as:

(printf)(("%d\n "), (a));


You missed one too ;-)

((printf)(("%d\ n"), (a)));

Nov 13 '05 #20

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

Similar topics

10
2626
by: LaEisem | last post by:
On-the-job, I have "inherited" a lot of old C language software. A question or two about when "casting" of null pointer constants is needed has occurred during behind-the-scenes cleanup of some of that software. That subject seems not to be addressed, at least not directly, in the C FAQ where FAQ 5.2 seems most relevant. References: * C FAQ 5.2 Null pointers (Including conditions where "casting" of null pointer...
15
6743
by: Greenhorn | last post by:
Hi, when a function doesn't specify a return type ,value what value is returned. In the below programme, the function sample()is returning the value passed to 'k'. sample(int); main() { int i = 0,j; j = sample(0);
40
3176
by: Mark P | last post by:
I'm implementing an algorithm and the computational flow is a somewhat deep. That is, fcn A makes many calls to fcn B which makes many calls to fcn C, and so on. The return value of the outermost fcn is a boolean and there are certain places within the inner functions where it may become apparent that the return value is false. In this case I'd like to halt the computation immediately and return false. My current approach is to have...
0
9980
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9826
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10830
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9641
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8018
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5855
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6061
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4276
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3283
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.