Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 28 Mar 2001 11:18:02 -0800 (PST)
From:      Linh Pham <lplist@closedsrc.org>
To:        j mckitrick <jcm@FreeBSD-uk.eu.org>
Cc:        <freebsd-questions@freebsd.org>
Subject:   Re: multiple C assignments in one statement
Message-ID:  <Pine.BSF.4.33.0103281114000.35388-100000@q.closedsrc.org>
In-Reply-To: <20010328201830.A76580@dogma.freebsd-uk.eu.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On 2001-03-28, j mckitrick scribbled:

# In the source code for the shortest DVD decoder to date, I saw statements
# with multiple assignments (not declarations) all separated by commas.  Does
# this have any advantage, other than allowing a bunch of assignments to be
# grouped in one statement without the need for braces?

Statements are set apart by semi-colons in C/C++ rather than commas.

The two blocks of code are the same:

int a, b, c;
a = 0;
b = 3;
c = a + b;

[is the same as]

int a, b, c; a = 0; b = 3; c = a + b;

For readability, it's best not to cram multiple statements onto one
line. If you want really compact code, then you can not only cram
multiple statements together (again, separated by semi-colons) but also
use obfuscated methods of doing the same thing as other functions.

Braces are normally used to separate code from another chunks of code,
like breaking code blocks into functions, etc.

-- 
Linh Pham
[lplist@closedsrc.org]

// 404b - Brain not found


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.33.0103281114000.35388-100000>