[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [MiNT] Programming style
- Subject: Re: [MiNT] Programming style
- From: Vincent Rivière <vincent.riviere@freesbee.fr>
- Date: Tue, 15 Dec 2009 14:55:00 +0100
- Cc: "[MiNT] Mailing-List" <mint@fishpool.com>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:sender:message-id:date:from :user-agent:mime-version:cc:subject:references:in-reply-to :content-type:content-transfer-encoding; bh=lIuTum/Mee3sGb17kaRhpvEwAlmyiIE4qpfBOqKORxw=; b=bSn1ZddsSnPM+iAIdmpK9HAtMC9i4jGlS4nv0fFkXT1e1ImHFSFIi6k0iR7eUoxc6X JaSwuyBqlhf652oOg9imQmHAG7v3j0uuF7XJojnx61Pyz3O2FlPsvewkwXC4LUxcqMJI a/Ar4TrA3YEon3eBP1cV5T+QGEKi67unwM2SI=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:message-id:date:from:user-agent:mime-version:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; b=MwLRaWX5VEAX8dSK6HCN95jkZZjKxGpPI48kZdxXYIVv40g7Ry4Q5DDPpNiYSB5iEF yyrRZsw9ffbdwUhYDzp8xB51vHpFuuDOloAckqHZc646oH3TlYQ3R9Vn//MRxujaKIjR qugkV1kGsfklKhUEeDjfY0bXe7h/zvKk+BOpg=
- In-reply-to: <BAB23262A0FA40C2BC2EF7F5A2D614D4@mercatus.local>
- List-help: <mailto:ecartis@lists.fishpool.fi?Subject=help>
- List-id: <mint.lists.fishpool.fi>
- List-owner: <mailto:tjhukkan@fishpool.fi>
- List-post: <mailto:mint@lists.fishpool.fi>
- List-subscribe: <mailto:mint-request@lists.fishpool.fi?Subject=subscribe>
- List-unsubscribe: <mailto:mint-request@lists.fishpool.fi?Subject=unsubscribe>
- References: <BAB23262A0FA40C2BC2EF7F5A2D614D4@mercatus.local>
- Sender: mint-bounce@lists.fishpool.fi
- User-agent: Thunderbird 2.0.0.23 (Windows/20090812)
Jo Even Skarstein wrote :
must I move the local static variable out of the
function, or is this OK?
Global variables are bad, because the cause reentrency problems.
Static global variables are a bit less bad, because they are local to a
single C file and can't be used by error from other sources.
Static variables defined inside functions are again a bit less bad,
because they are accessible only inside their function. However they are
still hidden global variables, and the reentrency problems are still here.
Static variables defined inside functions have an additional, less known
feature. They are initialized on the first function call. So at the
start of any function containing initialized static variables, there is
a hidden code like this:
if (!static_variables_initialized)
{
/* Initialize static variables */
static_variables_initialized = 1;
}
So because of this test, functions using initialized static local
variables are a bit slower as those using global variables. It just
involves an additional if(), so the difference is usually unnoticeable.
I made some tests about this feature long ago, I hope it is still valid
when using current compilers.
Personally, when I absolutely need some kind of global variable, I
prefer using a static variable inside a function, the source is cleaner.
--
Vincent Rivière