Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #150751
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: question list c |
| Date | 2020-03-22 21:42 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <87o8so3w3b.fsf@bsb.me.uk> (permalink) |
| References | <3b638332-166b-4420-9f4d-e75bfa8aa6a1@googlegroups.com> |
porinaxel@gmail.com writes:
> struct cell {
> int val;
> struct cell * next;
> };
> typedef struct cell cell_t; <---------- why there is structure cell_t
I don't understand the question. cell is what is called a struct tag.
It names a structure type, but it must be used with the keyword struct
struct cell c = { 42, NULL };
and so on. The author wants to give the type "struct cell" and simpler
name, "cell_t" so one could write
cell_t c = { 42, NULL };
instead. It's a common convention to use _t at the end of names that
name types.
> typedef struct cell * list;
Some people don't like hiding the fact that a type is a pointer type
like this.
> int car (list l){
> if (l) {
> return (*l).val;
> }
> else {
> return INT_MIN;
> }
> }
>
> liste cdr (list l){
> if (l) {
> return (* l).next;
> }
> else {
> return (list) 0;
> }
> }
> int listempty (list l){
> if (l) {
> return 0;
> }
> else {
> return 1;
> }
> }
> int listnonempty (list l){
> if (l) {
> return 1;
> }
> else {
> return 0;
> }
> }
The code won't compile and is very oddly written. Where is it from?
> i'dont understand any of this function pls help
That's too general a question. If you ask more specific questions the
question itself will help people to know how to answer. For example,
"what do all those {}s mean?" and "why is 0 being cast to a pointer
type?" show very different kinds of confusion.
--
Ben.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
question list c porinaxel@gmail.com - 2020-03-22 14:16 -0700
Re: question list c Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-03-22 21:42 +0000
Re: question list c porinaxel@gmail.com - 2020-03-26 05:40 -0700
Re: question list c Jorgen Grahn <grahn+nntp@snipabacken.se> - 2020-03-26 12:54 +0000
Re: question list c James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-03-26 09:21 -0400
Re: question list c Jorgen Grahn <grahn+nntp@snipabacken.se> - 2020-03-26 13:33 +0000
Re: question list c scott@slp53.sl.home (Scott Lurndal) - 2020-03-26 15:23 +0000
Re: question list c Anton Shepelev <anton.txt@g{oogle}mail.com> - 2020-03-26 19:12 +0300
Re: question list c mark.bluemel@gmail.com - 2020-03-26 07:27 -0700
Re: question list c Barry Schwarz <schwarzb@delq.com> - 2020-03-26 07:44 -0700
Re: question list c scott@slp53.sl.home (Scott Lurndal) - 2020-03-26 15:25 +0000
Re: question list c chad <cdalten@gmail.com> - 2020-03-26 15:17 -0700
Re: question list c John Bode <jfbode1029@gmail.com> - 2020-03-26 15:45 -0700
Re: question list c porinaxel@gmail.com - 2020-03-26 16:28 -0700
Re: question list c Barry Schwarz <schwarzb@delq.com> - 2020-03-26 16:53 -0700
csiph-web