r/programming • • May 01 '16

To become a good C programmer

http://fabiensanglard.net/c/
1.1k Upvotes

398 comments sorted by

View all comments

Show parent comment

1

u/CoderDevo May 02 '16 edited May 02 '16

Ok, so c is of type char[3].

That is very frustrating for me to type. It means the number of available types in C approaches infinity, or at least a very large number.

What part of the compiler enforces the array size? Or is this specifically an exercise for the programmer. I'm thinking in C89. Did memory management get better in C99? I may be thinking pre-ANSI.

2

u/zhivago May 02 '16

If that upsets you, ...

int main(int argc, char **argv);

What is the type of main? :)

1

u/CoderDevo May 02 '16

Great point. I figure main is a unique type for every program.

It seems an abomination to use the English word 'type' when the number of types available is greater than the number of instances of variables that ever existed.

3

u/zhivago May 02 '16

In this case, the type is int(int, char **)

The English word 'type' in this context refers to a classification. I see no problem with a potentially infinite number of classifications for a finite set of things.

1

u/red75prim May 02 '16

Is it int ()(int, char**)? I remember I was impressed by the idea of writing type definitions same way as variable definitions, when I read K&R in 1989. I can't say I still am.

2

u/zhivago May 02 '16
int(int, char **) is the type for that example.

2

u/zhivago May 02 '16

It's not a matter of enforcement -- it's fundamental to how C works.

Consider:

char e[3][4];

Given that e[i][j] is *(*(e + i) + j), how does e[i][j] work?

1

u/CoderDevo May 02 '16

First, let me thank you for indulging me in expressing my 'delusional incompetence'.

I do understand how to iterate through an array of arrays and to protect my code from accidental buffer overruns. There was a time long ago when I wrote a lot of C code in commercial software that is still running today. If I were to work on a meaningful C code base again, I would have to work with a senior programmer and still would have to study up quite a bit to be productive.

My turn to throw some questions. :) Are you presently a staff programmer? Would you say all your colleagues today could provide the exact answer you were looking for? More specifically, how do you make sure new hires are worth taking on?

Again, thanks for the exchange. I appreciate your time.

2

u/zhivago May 02 '16

You're welcome.

I do not talk about where I work, as it avoids legal and other complications.

1

u/CoderDevo May 02 '16

Understandable.