Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #105652
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Need explanation of C syntax for a Perl 6 guy |
| Date | 2017-03-09 10:22 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <87k27yzr4i.fsf@bsb.me.uk> (permalink) |
| References | <o9ql0c$di9$1@dont-email.me> |
T <T@invalid.invalid> writes:
<snip>
> int XStoreBuffer(Display *display, char *bytes,
> int nbytes, int buffer);
>
> char *XFetchBuffer(Display *display,
> int *nbytes_return, int buffer);
>
> Questions:
> 1) what does the * do to the variable?
It does something to the name. It indicates that the name has a more
complex type that the type sitting just to the left. C uses an odd
system in which things with types that are derived from the base types
(int, char, float and so on) are declared by decorating the name.
When you see "int ..." you know that the things being declared have
something to do with int (one of C's many integer types) but that's
all. The details are provided by the stuff around the name. For
example
int x; // x is an int
int *x; // x is a pointer to int
int x[3]; // x is an array of 3 ints
int *x[3]; // x is an array of 3 pointers to int
int (*x)[3]; // x is a pointer to an array of 3 ints (rare)
int x(void); // x is a function of no arguments
// that returns an int
int *x(void); // x is a function of no arguments
// that returns a pointer to int
int (*x)(void); // x is a pointer to a function of no arguments
// that returns an int.
(Note that, just like in expressions, parentheses are sometimes needed
because the things that go after a name []s and ()s bind more tightly
then * which goes in front.)
Some of the answers here have concentrated on the type, describing "T*"
as a "pointer to T" type. This fine as far as it goes, but it's less
helpful when
(a) you see mixed declarations like this:
char c, buf[1000], *bptr = &buf[0];
(b) the declaration is more complex like some of those above.
<snip>
--
Ben.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Need explanation of C syntax for a Perl 6 guy T <T@invalid.invalid> - 2017-03-08 20:20 -0800
Re: Need explanation of C syntax for a Perl 6 guy T <T@invalid.invalid> - 2017-03-08 20:57 -0800
Re: Need explanation of C syntax for a Perl 6 guy Barry Schwarz <schwarzb@dqel.com> - 2017-03-09 00:46 -0800
Re: Need explanation of C syntax for a Perl 6 guy gordonb.txjrp@burditt.org (Gordon Burditt) - 2017-03-09 03:29 -0600
Re: Need explanation of C syntax for a Perl 6 guy T <T@invalid.invalid> - 2017-03-09 12:39 -0800
Re: Need explanation of C syntax for a Perl 6 guy jt@toerring.de (Jens Thoms Toerring) - 2017-03-09 10:16 +0000
Re: Need explanation of C syntax for a Perl 6 guy T <T@invalid.invalid> - 2017-03-09 12:40 -0800
Re: Need explanation of C syntax for a Perl 6 guy T <T@invalid.invalid> - 2017-03-09 13:25 -0800
Re: Need explanation of C syntax for a Perl 6 guy jt@toerring.de (Jens Thoms Toerring) - 2017-03-10 21:02 +0000
Re: Need explanation of C syntax for a Perl 6 guy T <T@invalid.invalid> - 2017-03-10 17:49 -0800
Re: Need explanation of C syntax for a Perl 6 guy Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-03-09 10:22 +0000
Re: Need explanation of C syntax for a Perl 6 guy T <T@invalid.invalid> - 2017-03-09 12:40 -0800
Re: Need explanation of C syntax for a Perl 6 guy GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-03-09 12:48 +0100
Re: Need explanation of C syntax for a Perl 6 guy T <T@invalid.invalid> - 2017-03-09 12:43 -0800
Re: Need explanation of C syntax for a Perl 6 guy James Kuyper <jameskuyper@verizon.net> - 2017-03-10 10:22 -0500
Re: Need explanation of C syntax for a Perl 6 guy T <T@invalid.invalid> - 2017-03-10 11:47 -0800
Re: Need explanation of C syntax for a Perl 6 guy T <T@invalid.invalid> - 2017-03-10 12:42 -0800
Re: Need explanation of C syntax for a Perl 6 guy T <T@invalid.invalid> - 2017-03-10 19:52 -0800
Re: Need explanation of C syntax for a Perl 6 guy raltbos@xs4all.nl (Richard Bos) - 2017-03-09 12:09 +0000
Re: Need explanation of C syntax for a Perl 6 guy Keith Thompson <kst-u@mib.org> - 2017-03-09 09:05 -0800
Re: Need explanation of C syntax for a Perl 6 guy John Bode <jfbode1029@gmail.com> - 2017-03-09 12:31 -0800
Re: Need explanation of C syntax for a Perl 6 guy T <T@invalid.invalid> - 2017-03-09 12:41 -0800
Re: Need explanation of C syntax for a Perl 6 guy Paul <nospam@needed.invalid> - 2017-03-10 04:06 -0500
Re: Need explanation of C syntax for a Perl 6 guy T <T@invalid.invalid> - 2017-03-10 12:42 -0800
Re: Need explanation of C syntax for a Perl 6 guy jt@toerring.de (Jens Thoms Toerring) - 2017-03-10 21:35 +0000
Re: Need explanation of C syntax for a Perl 6 guy T <T@invalid.invalid> - 2017-03-10 17:48 -0800
Re: Need explanation of C syntax for a Perl 6 guy John Bode <jfbode1029@gmail.com> - 2017-03-10 14:54 -0800
Re: Need explanation of C syntax for a Perl 6 guy T <T@invalid.invalid> - 2017-03-10 17:43 -0800
Re: Need explanation of C syntax for a Perl 6 guy James Kuyper <jameskuyper@verizon.net> - 2017-03-10 21:11 -0500
csiph-web