linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Glynn Clements <glynn@gclements.plus.com>
To: Nate Jenkins <nate@uniwest.com>
Cc: C programming list <linux-c-programming@vger.kernel.org>
Subject: Re: type qualifiers on function return types?
Date: Fri, 9 Dec 2005 19:25:54 +0000	[thread overview]
Message-ID: <17305.55874.776271.548409@cerise.gclements.plus.com> (raw)
In-Reply-To: <001401c5fc1e$d7963110$8e01a8c0@Nate>


Nate Jenkins wrote:

> I am sure I am not the only one here wondering what "type qualifiers" are.
> Could someone expound on what they are and why one would use them?

For a precise definition, see §6.7.3 of the C99 draft, at:

	http://www.open-std.org/jtc1/sc22/open/n2794/n2794.txt

The most useful is "const", which tells the compiler to generate a
warning if anything tries to modify the target. Also, if a function
argument is a pointer to a const target, the compiler can assume that
the target will not be modified.

The "volatile" qualifier indicates that any reads or writes must be
performed exactly as indicated by the code, and cannot be optimised
away (e.g. caching the value in a register).

It is used if the target can be read or written by mechanisms which
aren't visible to the compiler (hardware, other threads, signal
handlers, etc).

The "restrict" qualifier is new in C99 and allows additional
optimisations. It only applies to pointers, and asserts that the
location to which the pointer points will only be read or written
through that pointer.

-- 
Glynn Clements <glynn@gclements.plus.com>
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2005-12-09 19:25 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-12-08 12:32 type qualifiers on function return types? Robert P. J. Day
2005-12-08 16:58 ` Steve Graegert
2005-12-08 17:43   ` Nate Jenkins
2005-12-08 18:00     ` Robert P. J. Day
2005-12-08 18:07     ` Steve Graegert
2005-12-08 18:16       ` Nate Jenkins
2005-12-09 19:25     ` Glynn Clements [this message]
2005-12-08 17:58   ` Robert P. J. Day
2005-12-09 19:03     ` Glynn Clements
2005-12-09 19:04       ` Robert P. J. Day

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=17305.55874.776271.548409@cerise.gclements.plus.com \
    --to=glynn@gclements.plus.com \
    --cc=linux-c-programming@vger.kernel.org \
    --cc=nate@uniwest.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;
as well as URLs for NNTP newsgroup(s).