MESSAGE
DATE | 2015-06-26 |
FROM | Ruben Safir
|
SUBJECT | Subject: [LIU Comp Sci] Fwd: strange function types in unistd.h
|
From owner-learn-outgoing-at-mrbrklyn.com Fri Jun 26 18:24:36 2015 Return-Path: X-Original-To: archive-at-mrbrklyn.com Delivered-To: archive-at-mrbrklyn.com Received: by mrbrklyn.com (Postfix) id B1FB616117E; Fri, 26 Jun 2015 18:24:36 -0400 (EDT) Delivered-To: learn-outgoing-at-mrbrklyn.com Received: by mrbrklyn.com (Postfix, from userid 28) id 93FEB161182; Fri, 26 Jun 2015 18:24:36 -0400 (EDT) Delivered-To: learn-at-nylxs.com Received: from mailbackend.panix.com (mailbackend.panix.com [166.84.1.89]) by mrbrklyn.com (Postfix) with ESMTP id C273916117E; Fri, 26 Jun 2015 18:24:09 -0400 (EDT) Received: from [10.0.0.19] (www.mrbrklyn.com [96.57.23.82]) by mailbackend.panix.com (Postfix) with ESMTPSA id 6D9BF13C67; Fri, 26 Jun 2015 18:24:09 -0400 (EDT) Message-ID: <558DD109.9090407-at-panix.com> Date: Fri, 26 Jun 2015 18:24:09 -0400 From: Ruben Safir User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: Hangout , learn-at-nylxs.com Subject: [LIU Comp Sci] Fwd: strange function types in unistd.h References: <2pumoado7dtlvqaujvgq58gup7c2m73rmq-at-4ax.com> In-Reply-To: X-Forwarded-Message-Id: <2pumoado7dtlvqaujvgq58gup7c2m73rmq-at-4ax.com> Content-Type: multipart/mixed; boundary="------------020509010101040605070305" Sender: owner-learn-at-mrbrklyn.com Precedence: bulk Reply-To: learn-at-mrbrklyn.com
This is a multi-part message in MIME format. --------------020509010101040605070305 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit
Just something worth bringing to your attention and for learning about advanced C programming in Unix and GCC
--------------020509010101040605070305 Content-Type: message/rfc822; name="strange function types in unistd_h.eml" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="strange function types in unistd_h.eml"
Path: reader1.panix.com!panix!not-for-mail From: ruben safir Newsgroups: comp.unix.programmer Subject: strange function types in unistd.h Date: Wed, 24 Jun 2015 23:39:08 -0400 Organization: PANIX Public Access Internet and UNIX, NYC Message-ID: NNTP-Posting-Host: www.mrbrklyn.com Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Trace: reader1.panix.com 1435203548 28127 96.57.23.82 (25 Jun 2015 03:39:08 GMT) X-Complaints-To: abuse-at-panix.com NNTP-Posting-Date: Thu, 25 Jun 2015 03:39:08 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 Xref: panix comp.unix.programmer:234761
Can someone walk me through the exact meaning of this line
279 /* Values for the second argument to access. 280 These may be OR'd together. */ 281 #define R_OK 4 /* Test for read permission. */ 282 #define W_OK 2 /* Test for write permission. */ 283 #define X_OK 1 /* Test for execute permission. */ 284 #define F_OK 0 /* Test for existence. */ 285 286 /* Test for access to NAME using the real UID and real GID. */ 287 extern int access (const char *__name, int __type) __THROW __nonnull ((1)); 288
287 - throw and nonnul? I'm not familiar with this C syntax
Ruben
--------------020509010101040605070305 Content-Type: message/rfc822; name="Re: strange function types in unistd_h.eml" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="Re: strange function types in unistd_h.eml"
Path: reader1.panix.com!panix!goblin1!goblin.stu.neva.ru!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Barry Schwarz Newsgroups: comp.unix.programmer Subject: Re: strange function types in unistd.h Date: Wed, 24 Jun 2015 21:00:59 -0700 Organization: A noiseless patient Spider Message-ID: <2pumoado7dtlvqaujvgq58gup7c2m73rmq-at-4ax.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Injection-Info: mx02.eternal-september.org; posting-host="1778e2eb2af8532fd406f5566d5298e8"; logging-data="29794"; mail-complaints-to="abuse-at-eternal-september.org"; posting-account="U2FsdGVkX19wFc9wriYPjpkh2Mho5fCmylful3xF7tw=" X-Newsreader: Forte Agent 4.2/32.1118 Cancel-Lock: sha1:i8AhyRRjbCh01HQNbh1dF4F1jww= Xref: panix comp.unix.programmer:234762
On Wed, 24 Jun 2015 23:39:08 -0400, ruben safir wrote:
>Can someone walk me through the exact meaning of this line > > > 279 /* Values for the second argument to access. > 280 These may be OR'd together. */ > 281 #define R_OK 4 /* Test for read permission. */ > 282 #define W_OK 2 /* Test for write permission. */ > 283 #define X_OK 1 /* Test for execute permission. */ > 284 #define F_OK 0 /* Test for existence. */ > 285 > 286 /* Test for access to NAME using the real UID and real GID. */ > 287 extern int access (const char *__name, int __type) __THROW >__nonnull ((1)); > 288 > >287 - throw and nonnul? I'm not familiar with this C syntax
C is case sensitive and the underscores are part of the tokens. So it is __THROW and __nonnull (with two ells).
The standard reserves tokens starting with two underscores for extensions provided by the implementation. These fit that definition.
Just as a guess, it appears that __nonull directs the compiler to generate some additional code when the function named access is called. This code would verify that argument 1 is not NULL. __THROW probably identifies the action if the verification fails.
-- Remove del for email
--------------020509010101040605070305 Content-Type: message/rfc822; name="Re: strange function types in unistd_h.eml" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="Re: strange function types in unistd_h.eml"
Path: reader1.panix.com!panix!not-for-mail From: ruben safir Newsgroups: comp.unix.programmer Subject: Re: strange function types in unistd.h Date: Thu, 25 Jun 2015 01:04:58 -0400 Organization: PANIX Public Access Internet and UNIX, NYC Message-ID: References: <2pumoado7dtlvqaujvgq58gup7c2m73rmq-at-4ax.com> NNTP-Posting-Host: www.mrbrklyn.com Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-Trace: reader1.panix.com 1435208698 29192 96.57.23.82 (25 Jun 2015 05:04:58 GMT) X-Complaints-To: abuse-at-panix.com NNTP-Posting-Date: Thu, 25 Jun 2015 05:04:58 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 In-Reply-To: <2pumoado7dtlvqaujvgq58gup7c2m73rmq-at-4ax.com> Xref: panix comp.unix.programmer:234763
On 06/25/2015 12:00 AM, Barry Schwarz wrote: > The standard reserves tokens starting with two underscores for > extensions provided by the implementation.
the implementation in this case is gcc?
--------------020509010101040605070305 Content-Type: message/rfc822; name="Re: strange function types in unistd_h.eml" Content-Transfer-Encoding: 8bit Content-Disposition: attachment; filename="Re: strange function types in unistd_h.eml"
Path: reader1.panix.com!panix!goblin2!goblin.stu.neva.ru!porbandar.httrack.net!montbard.httrack.net!news.httrack.net!.POSTED!not-for-mail From: Xavier Roche Newsgroups: comp.unix.programmer Subject: Re: strange function types in unistd.h Date: Thu, 25 Jun 2015 07:25:12 +0200 Organization: Nowhere Corp. Message-ID: References: <2pumoado7dtlvqaujvgq58gup7c2m73rmq-at-4ax.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit X-Trace: news.httrack.net 1435209912 9205 2a00:4b00:13c:cc:5d61:8c47:d045:a92f (25 Jun 2015 05:25:12 GMT) X-Complaints-To: usenet-at-httrack.com NNTP-Posting-Date: Thu, 25 Jun 2015 05:25:12 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 In-Reply-To: Xref: panix comp.unix.programmer:234764
Le 25/06/2015 07:04, ruben safir a ?crit : > the implementation in this case is gcc?
Yes, mostly. __nonnull is just expanding to nonnull attributes
/usr/include/sys/cdefs.h:
#if __GNUC_PREREQ (3,3) # define __nonnull(params) __attribute__ ((__nonnull__ params)) ...
See
nonnull (arg-index, ...) The nonnull attribute specifies that some function parameters should be non-null pointers. For instance, the declaration: extern void * my_memcpy (void *dest, const void *src, size_t len) __attribute__((nonnull (1, 2))); causes the compiler to check that, in calls to my_memcpy, arguments dest and src are non-null. If the compiler determines that a null pointer is passed in an argument slot marked as non-null, and the -Wnonnull option is enabled, a warning is issued. The compiler may also choose to make optimizations based on the knowledge that certain function arguments will not be null.
If no argument index list is given to the nonnull attribute, all pointer arguments are marked as non-null. To illustrate, the following declaration is equivalent to the previous example:
extern void * my_memcpy (void *dest, const void *src, size_t len) __attribute__((nonnull));
[ Note on '__attribute__ ((__nonnull__' :
You may also specify attributes with `__' preceding and following each keyword. This allows you to use them in header files without being concerned about a possible macro of the same name. For example, you may use __noreturn__ instead of noreturn. ]
--------------020509010101040605070305--
|
|