linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Nate Jenkins" <nate@uniwest.com>
To: C programming list <linux-c-programming@vger.kernel.org>
Subject: Re: type qualifiers on function return types?
Date: Thu, 8 Dec 2005 10:16:09 -0800	[thread overview]
Message-ID: <007301c5fc23$769490f0$8e01a8c0@Nate> (raw)
In-Reply-To: 6a00c8d50512081007v1d59190fh428935aa74d0cf9c@mail.gmail.com


>> 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?
>
> My DEC C Compiler documentation gives a good intro to type qualifiers.
> Here is what is says:
>
> There are four type qualifiers:
>
>    * const
>    * volatile
>    * __unaligned (axp)
>    * __restrict (pointer type only) [now: restrict]
>
> "Type qualifiers were introduced by the ANSI C standard to, in part,
> give you greater control over the compiler's optimizations. The const
> and volatile type qualifiers can be applied to any type. The
> __restrict type qualifier can be applied only to pointer types.
>
> Note that because the __restrict type qualifier is not part of the
> 1989 ANSI C standard, this keyword has double leading underscores. The
> next version (9X) of the C standard is expected to adopt the keyword
> restrict with the same semantics described in this section.
>
> The use of const gives you a method of controlling write access to an
> object, and eliminates potential side effects across function calls
> involving that object. This is because a side effect is an alteration
> of an object's storage and const prohibits such alteration.
>
> Use volatile to qualify an object that can be changed by other
> processes or hardware. The use of volatile disables optimizations with
> respect to referencing the object. If an object is volatile qualified,
> it may be changed between the time it is initialized and any
> subsequent assignments. Therefore, it cannot be optimized."
>
> I hope this info was useful enough.
>
> \Steve
>
> PS: Please do not top post.  Thanks.
>
> --
>
> Steve Graegert <graegerts@gmail.com> | Blog <http://tikomi.org>
> Software Consultant {C/C++ && Java && .NET}
> Office: +49 9131 7123988
> Mobile: +49 1520 9289212
>
>

Thanks for the info Robert and Steve.  Sometimes I forget the fancy names of 
these things.  Yes, "const" is probably the most commonly used one...

Nate


  reply	other threads:[~2005-12-08 18:16 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 [this message]
2005-12-09 19:25     ` Glynn Clements
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='007301c5fc23$769490f0$8e01a8c0@Nate' \
    --to=nate@uniwest.com \
    --cc=linux-c-programming@vger.kernel.org \
    /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).