public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Richard Knutsson <ricknu-0@student.ltu.se>
To: "Moore, Robert" <robert.moore@intel.com>
Cc: Len Brown <lenb@kernel.org>,
	linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org
Subject: Re: [PATCH] [ACPI] utilities/: Compliment va_start() with va_end().
Date: Tue, 27 Nov 2007 01:15:48 +0100	[thread overview]
Message-ID: <474B61B4.9020309@student.ltu.se> (raw)
In-Reply-To: <B28E9812BAF6E2498B7EC5C427F293A403BCB8FA@orsmsx415.amr.corp.intel.com>

Moore, Robert wrote:
> This is an interesting one to me.
>
> From various documentation:
>
> After all arguments have been retrieved, va_end resets the pointer to
> NULL.
>
> va_end
> Each invocation of va_start must be matched by a corresponding
> invocation of va_end in the same function. After the call va_end(ap) the
> variable ap is undefined. Multiple transversals of the list, each
> bracketed by va_start and va_end are possible. va_end may be a macro or
> a function.   
>
> Now, I'm all for defensive programming, but I don't really see the point
> of va_end when the list will be only traversed once.
>
>   
First off, I think it is a good idea to follow the documentation, which stated:
"va_end
Each invocation of va_start must be matched by a corresponding
invocation of va_end in the same function."

Then if it is not really needed, does it take up extra cycles?
"In practice, with most C compilers, calling |va_end| does nothing
and you do not really need to call it.  This is always true in the GNU C
compiler."[1]

Portability:
"But you might as well call |va_end| just in case your
program is someday compiled with a peculiar compiler."[2]
This argument is not as likely thou, but who knows? (Since I guess Intel's
compiler is included in the 'most C compilers')

>
> We don't set all local pointers to NULL at function exit, what is the
> point of doing it here?
>   
I think it is a good thing if the code follows the documentation, both 
for the person who tries
to understand the code (to see when the 'args' is no longer needed and 
not getting confused
by the absent of va_end(), after all, IMHO we should write the code how 
we want things to
work and let the compiler do the optimizations (it usually does a better 
job at it then we do))
and to automated searches (that is how I found this one).
> I suppose some implementation could allocate memory at va_start, but in
> practice, does this happen?
>   
Not sure what you mean.
> Bob
>
>   
cu
Richard Knutsson

[1] 
http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_28.html
[2] The rest of [1]'s line.


  reply	other threads:[~2007-11-27  0:28 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <200711250205.34299.lenb@kernel.org>
2007-11-26 22:14 ` [PATCH] [ACPI] utilities/: Compliment va_start() with va_end() Moore, Robert
2007-11-27  0:15   ` Richard Knutsson [this message]
2007-11-27  0:52     ` Moore, Robert
2007-11-27  2:10       ` Richard Knutsson
2007-11-24 20:43 Richard Knutsson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=474B61B4.9020309@student.ltu.se \
    --to=ricknu-0@student.ltu.se \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robert.moore@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox