public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* expalin this syntax pls
@ 2002-10-17 23:32 Nathan .
  2002-10-18  4:23 ` Jim Wilson
  0 siblings, 1 reply; 7+ messages in thread
From: Nathan . @ 2002-10-17 23:32 UTC (permalink / raw)
  To: gcc

Hello All,

Is it correct to leave a space in declaring args to following function. This 
has been cut paste from  file  /usr/include/netdb.h.
Quite surprisingly there is no compilation error but please explain me this 
novel syntax. All these lines have a space ..looks a space if not some 
invisible character. plz expalin this anomally. e.g there is a space between 
__restrict and __name ..

======= from /usr/include/netdb.h ===================
extern int gethostbyname_r (__const char *__restrict __name,   <<<<see this 
line
                            struct hostent *__restrict __result_buf,        
<<<<see this line
                            char *__restrict __buf, size_t __buflen,
                            struct hostent **__restrict __result,            
  <<<<see this line
                            int *__restrict __h_errnop) __THROW;

==================================================


Thanks for ur patience
Please Advise,
-Nitin








_________________________________________________________________
Get faster connections -- switch to MSN Internet Access! 
http://resourcecenter.msn.com/access/plans/default.asp

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: expalin this syntax pls
  2002-10-17 23:32 expalin this syntax pls Nathan .
@ 2002-10-18  4:23 ` Jim Wilson
  2002-10-18 14:27   ` restrict keyword [was: expalin this syntax pls] Joe Buck
  0 siblings, 1 reply; 7+ messages in thread
From: Jim Wilson @ 2002-10-18  4:23 UTC (permalink / raw)
  To: Nathan .; +Cc: gcc

restrict is a new keyword in ISO C99.  It is a type qualifier, like const
and volatile.  See the ISO C99 standard, or see a book that explains the
ISO C99 language.  This is the current version of the C language.  It became
a standard in 1999.

Jim

^ permalink raw reply	[flat|nested] 7+ messages in thread

* restrict keyword [was: expalin this syntax pls]
  2002-10-18  4:23 ` Jim Wilson
@ 2002-10-18 14:27   ` Joe Buck
  2002-10-18 18:46     ` Joseph S. Myers
  2002-10-18 23:07     ` kwall
  0 siblings, 2 replies; 7+ messages in thread
From: Joe Buck @ 2002-10-18 14:27 UTC (permalink / raw)
  To: Jim Wilson; +Cc: Nathan ., gcc

Jim Wilson writes:

> restrict is a new keyword in ISO C99.  It is a type qualifier, like const
> and volatile.  See the ISO C99 standard, or see a book that explains the
> ISO C99 language.  This is the current version of the C language.  It became
> a standard in 1999.

Folks who want a quick-and-dirty explanation of what "restrict" does
(good enough for intuition, but not for a compiler writer) can see

http://www.devx.com/free/tips/tipview.asp?content_id=2554

By the way, there's a similar issue with "restrict" to the various
battles we've had over type-based aliasing: should gcc warn about
obvious violations?

Consider rtest.c
-----------------------------------------------
void f(const int* restrict pci, int* restrict pi);

int main()
{
	int n;
	f(&n, &n);
}
-----------------------------------------------

This is not a legal program: f's arguments are restricted pointers,
meaning that we promise the compiler that there is some data that
can be accessed only through pci, and other data that can be accessed
only through pi, yet we pass the same value to both pointers.
But gcc does not attempt to diagnose this:

gcc -Wall --std=c99 -c -O rtest.c

gives no warnings (in gcc 3.2).  Would it be worth trying to warn?  Of
course, the issue is that the warning could only be generated in simple
cases, or perhaps in somewhat more complicated cases if we're doing value
range propagation or the like, but in general only when the compiler can
tell exactly what each pointer points to.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: restrict keyword [was: expalin this syntax pls]
  2002-10-18 14:27   ` restrict keyword [was: expalin this syntax pls] Joe Buck
@ 2002-10-18 18:46     ` Joseph S. Myers
  2002-10-18 21:53       ` Joe Buck
  2002-10-18 23:07     ` kwall
  1 sibling, 1 reply; 7+ messages in thread
From: Joseph S. Myers @ 2002-10-18 18:46 UTC (permalink / raw)
  To: Joe Buck; +Cc: gcc

On Fri, 18 Oct 2002, Joe Buck wrote:

> Consider rtest.c
> -----------------------------------------------
> void f(const int* restrict pci, int* restrict pi);
> 
> int main()
> {
> 	int n;
> 	f(&n, &n);
> }
> -----------------------------------------------
> 
> This is not a legal program: f's arguments are restricted pointers,
> meaning that we promise the compiler that there is some data that
> can be accessed only through pci, and other data that can be accessed
> only through pi, yet we pass the same value to both pointers.

It's a perfectly legal program if f doesn't actually write through pi
(missing an optional const).  Remember that the definition of restrict was
changed substantially between the last public draft and the FDIS (at the
instigation of the UK) to a model where there can be readonly access
through multiple restricted pointers unless the data is written to.

-- 
Joseph S. Myers
jsm28@cam.ac.uk

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: restrict keyword [was: expalin this syntax pls]
  2002-10-18 18:46     ` Joseph S. Myers
@ 2002-10-18 21:53       ` Joe Buck
  2002-10-18 21:55         ` Joseph S. Myers
  0 siblings, 1 reply; 7+ messages in thread
From: Joe Buck @ 2002-10-18 21:53 UTC (permalink / raw)
  To: Joseph S. Myers; +Cc: Joe Buck, gcc

I wrote:
> > Consider rtest.c
> > -----------------------------------------------
> > void f(const int* restrict pci, int* restrict pi);
> > 
> > int main()
> > {
> > 	int n;
> > 	f(&n, &n);
> > }
> > -----------------------------------------------
> > 
> > This is not a legal program: f's arguments are restricted pointers,
> > meaning that we promise the compiler that there is some data that
> > can be accessed only through pci, and other data that can be accessed
> > only through pi, yet we pass the same value to both pointers.

Joseph S. Myers writes:
> It's a perfectly legal program if f doesn't actually write through pi
> (missing an optional const).  Remember that the definition of restrict was
> changed substantially between the last public draft and the FDIS (at the
> instigation of the UK) to a model where there can be readonly access
> through multiple restricted pointers unless the data is written to.

This means that we can't issue a hard error for it, but a warning may well
still be appropriate.  Errors are for code that is wrong, warnings are for
code that is likely to be wrong. If you insist on not issuing warnings for
such code, we have the problem that we can't use similar mechanisms to
warn about possible misuse of memcpy, whose specification implies
"restrict" even for C++, which doesn't have the keyword.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: restrict keyword [was: expalin this syntax pls]
  2002-10-18 21:53       ` Joe Buck
@ 2002-10-18 21:55         ` Joseph S. Myers
  0 siblings, 0 replies; 7+ messages in thread
From: Joseph S. Myers @ 2002-10-18 21:55 UTC (permalink / raw)
  To: Joe Buck; +Cc: gcc

On Fri, 18 Oct 2002, Joe Buck wrote:

> This means that we can't issue a hard error for it, but a warning may well
> still be appropriate.  Errors are for code that is wrong, warnings are for
> code that is likely to be wrong. If you insist on not issuing warnings for
> such code, we have the problem that we can't use similar mechanisms to
> warn about possible misuse of memcpy, whose specification implies
> "restrict" even for C++, which doesn't have the keyword.

You can't issue a hard error for it anyway, since the code might never be 
executed.  The key questions for issuing a warning (under its own option, 
possibly included in -Wall) are:

* Does anyone write real (broken) code the warning would detect?  (The 
relevant question for having the warning at all.)
* Does anyone write real (working) code the warning would wrongly trigger 
on?
* How common are these?
* Can working code wrongly triggering the warning be easily changed, even 
if automatically generated, so as not to trigger it?  (The relevant 
question for -Wall inclusion.)

In the case of memcpy, we have more information to tell whether a call
*is* a problem (rather than might be).

-- 
Joseph S. Myers
jsm28@cam.ac.uk

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: restrict keyword [was: expalin this syntax pls]
  2002-10-18 14:27   ` restrict keyword [was: expalin this syntax pls] Joe Buck
  2002-10-18 18:46     ` Joseph S. Myers
@ 2002-10-18 23:07     ` kwall
  1 sibling, 0 replies; 7+ messages in thread
From: kwall @ 2002-10-18 23:07 UTC (permalink / raw)
  To: gcc

On Fri, Oct 18, 2002 at 10:41:11AM -0700, Joe Buck wrote:
> Jim Wilson writes:
> 
> > restrict is a new keyword in ISO C99.  It is a type qualifier, like const
> > and volatile.  See the ISO C99 standard, or see a book that explains the
> > ISO C99 language.  This is the current version of the C language.  It became
> > a standard in 1999.
> 
> Folks who want a quick-and-dirty explanation of what "restrict" does
> (good enough for intuition, but not for a compiler writer) can see
> 
> http://www.devx.com/free/tips/tipview.asp?content_id=2554

Thanks muchly, Joe. I wondered about the restrict keyword...

Kurt
-- 
For 20 dollars, I'll give you a good fortune next time ...

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2002-10-19  0:29 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-17 23:32 expalin this syntax pls Nathan .
2002-10-18  4:23 ` Jim Wilson
2002-10-18 14:27   ` restrict keyword [was: expalin this syntax pls] Joe Buck
2002-10-18 18:46     ` Joseph S. Myers
2002-10-18 21:53       ` Joe Buck
2002-10-18 21:55         ` Joseph S. Myers
2002-10-18 23:07     ` kwall

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 read-only IMAP folder(s) and NNTP newsgroup(s).