0

why can't we change the default starting index of an array to 1 instead of 0 ?
and another question how much fields can a bit field have ay most ?
thanks previously

Edited by Adam_35

4
Contributors
4
Replies
19
Views
1 Week
Discussion Span
Last Post by pty
1

This is a common question for a new C or other language programmer. To know why I guess you could find books on the history of C and how it came to be. But it's mostly historic and you can code as you see fit. However, it is best to not fight the tide this time and learn how to code using the standard calls and accept that arrays and more start at zero.

As to the bit field question, that varies with the storage you chose. For Integer Types (noted at https://www.tutorialspoint.com/cprogramming/c_data_types.htm ) you have 1 to 4 bytes and since a byte (for most machines) is 8 bits that would be 8 fields per byte.

This can be considered arcana today by some. Let's say you are programming on an average PC today. Not much reason to encode data into bit fields. Just use variables to clearly state what you mean. In embedded programming bit fields are not going away. Some will open a debate on this. I think this quote applies here.

This has made a lot of people very angry and been widely regarded as a bad move.

Douglas Adams

Edited by rproffitt: Spelling

0

Going back to Kernighan & Ritchie...

An array name is a pointer expression ... a reference to an array is converted by the compiler to a pointer to the beginning of the array ... a reference to a[i] can also be written as *(a+i)

Obviously this implies that the first element of an array MUST be [0]

Edited by JamesCherrill

0

@rproffitt Thanks for the clearance i see now so it's just all about the makers and that's that, just seems we should use it the way it was invented to be heh.

1

You could always switch to a language where indexing starts at 1. FORTRAN, Lua, Pascal and Smalltalk to name a few.

Votes + Comments
Oh Pascal, where I spent too much time.
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.