Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | "Bill Cunningham" <nospam@nspam.invalid> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: declarator |
| Date | 2015-06-29 18:39 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <mmshbp$o4d$1@dont-email.me> (permalink) |
| References | <mmq8l7$qcm$1@dont-email.me> <87d20eesim.fsf@bsb.me.uk> <mms93e$k2m$1@dont-email.me> <p2c3pa578rsfhdkfq2olp0bb9vq710lfec@4ax.com> |
"Barry Schwarz" <schwarzb@dqel.com> wrote in message
news:p2c3pa578rsfhdkfq2olp0bb9vq710lfec@4ax.com...
> On Mon, 29 Jun 2015 16:18:13 -0400, "Bill Cunningham"
> <nospam@nspam.invalid> wrote:
>
>>
>>"Ben Bacarisse" <ben.usenet@bsb.me.uk> wrote in message
>>news:87d20eesim.fsf@bsb.me.uk...
>>> "Bill Cunningham" <nospam@nspam.invalid> writes:
>>>
>>>> Ok I came across a new term today. I know of dereferences and
>>>> declarations. But declarator?
>>>
>>> The declarator is the part of a declaration that is syntactically
>>> attached to the name. It includes that parts that say that a name (or
>>> type) is a pointer or an array or a function, together with qualifiers
>>> like const when they apply to those parts of the type. In
>>>
>>> const int x = 42, *const ip = &x, (*f)(void);
>>>
>>> the "const int" part apples to all the declarations. It's called a type
>>> specifier and it includes a type qualifier. The parts "x", "*const ip"
>>> and "(*f)(void)" are three declarators. Two of the declared objects are
>>> initialised.
>>
>> So I would say here. All return ints. The "function pointer." would be
>
> What do you mean "All"? Return is an action performed by a function.
> Since neither x nor ip is a function, they don't return anything.
Ok I guess yes you are correct. The pointers point to their declared
type.
>>"f" pointing to a function that returns int and takes no arguments.
>>
>>int printthis (void) {...} //declaration and body of function
>>
>>printthis *f (void); //initialization right? or...
>
> Not even close. This declares f as a function that takes no arguments
> and returns a pointer to something of type printthis. Since printthis
> is not a type, this is a syntax error
>
> Initialization is part of the declaration. You would need the
> declaration to look like
> const int (*f)(void) = printthis;
> If you wish to assign a value to f after it is defined, use the
> original declaration and an assignment statement such as
> f = printthis;
>
>>printhis (*f) (void);
>
> This is no better. This declares f as a pointer to function taking no
> arguments and returning a value of type printhis. As above, it is
> just syntax error. Changing printhis to printthis makes no
> difference.
>
>>Now if those parenthesis around "*f" are needed can someone give a quick
>
> Look at the two above. What does the * apply to? Without the
> parentheses, it applies to the return type (f returns a pointer). With
> the parentheses, it applies to the name being declared (f is a
> pointer).
Yes I see now. I didn't catch that. f would simply be a function.
>>help. The API I am looking at has an /optional/ pointer to dunction in
>>it's
>>code. Coding does not require using it.
>
> What is an optional pointer?
Optional to use the function pointer in coding. There are other
interfaces. That is a good question.
Is it like the third argument to strtol
> which either points to a char* or is NULL? This argument is not
> optional. It must be present in the function call. The only option
> is if it points to something or not.
>
> Whatever it is, if you don't need to use it, you shouldn't need to
> define it. If you do need to use it, you will have provide more
> details.
Bill
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
declarator "Bill Cunningham" <nospam@nspam.invalid> - 2015-06-28 21:58 -0400
declarator "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-06-28 19:14 -0700
Re: declarator "Bill Cunningham" <nospam@nspam.invalid> - 2015-06-28 22:36 -0400
Re: declarator "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-06-28 19:46 -0700
Re: declarator Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-06-29 11:22 +0100
Re: declarator "Bill Cunningham" <nospam@nspam.invalid> - 2015-06-29 16:07 -0400
Re: declarator "Bill Cunningham" <nospam@nspam.invalid> - 2015-06-29 16:09 -0400
Re: declarator Barry Schwarz <schwarzb@dqel.com> - 2015-06-28 21:51 -0700
Re: declarator Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-06-29 11:08 +0100
Re: declarator "Bill Cunningham" <nospam@nspam.invalid> - 2015-06-29 16:18 -0400
Re: declarator Barry Schwarz <schwarzb@dqel.com> - 2015-06-29 14:23 -0700
Re: declarator "Bill Cunningham" <nospam@nspam.invalid> - 2015-06-29 18:39 -0400
Re: declarator "Bill Cunningham" <nospam@nspam.invalid> - 2015-06-29 20:39 -0400
Re: declarator Keith Thompson <kst-u@mib.org> - 2015-06-29 19:01 -0700
Re: declarator "Bill Cunningham" <nospam@nspam.invalid> - 2015-06-29 22:13 -0400
Re: declarator Barry Schwarz <schwarzb@dqel.com> - 2015-06-29 20:45 -0700
Re: declarator Keith Thompson <kst-u@mib.org> - 2015-06-30 08:22 -0700
Re: declarator Tim Rentsch <txr@alumni.caltech.edu> - 2015-07-11 08:44 -0700
Re: declarator "Bill Cunningham" <nospam@nspam.invalid> - 2015-06-30 12:48 -0400
Re: declarator Barry Schwarz <schwarzb@dqel.com> - 2015-06-30 15:32 -0700
Re: declarator John Bode <jfbode1029@gmail.com> - 2015-07-01 13:50 -0700
Re: declarator gazelle@shell.xmission.com (Kenny McCormack) - 2015-07-01 21:57 +0000
Re: declarator "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-07-01 15:05 -0700
Re: declarator "Bill Cunningham" <nospam@nspam.invalid> - 2015-07-02 20:34 -0400
Re: declarator Jens Stuckelberger <Jens_Stuckelberger@nowhere.net> - 2015-06-29 14:55 +0000
csiph-web