https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57853

--- Comment #18 from this is me <brodhow at sbcglobal dot net> ---
This is why C arrays are not pointers. It was possible to easily misconstrue
datatypes like especially with imported variables. Defined as a short integer
in one file but, is being used as a character in another file. Here, the 1
datatype width (in "++") here can be narrower with a short integer so when the
cpu tries access a wider character's datatype width then, thats where
segmentation faults or bus errors come from! 

 Seg faults can still happen even now with the extreme datatype checking
between calling arguments and received parameters! How? Like when defining a
structure then using it! Before allocating any memory for it, still!  Some
things never change.

 So, a pointer can point to anything but, they're not all of the same datatype
width nature! This is what C arrays are not pointers! C arrays can hold any
type of data too! Where the indexing uses different number values as to which
datatype it is. See "Expert C Programming" by Peter Van Der Linden. Where he
says that it is shocking! C arrays are not pointers!

He also says that the C array indexing is based on a commutative math formula
where a + b = c and b + a = c! Or, here absolute address + datatypewidth offset
= relative address or datatypewidth offset + absolute address = relative
address! As in:

#include <stdio.h>

void main(){

  char cat[4] = {'C', 'A', 'T' };
  int i = 0;

  printf("the char is %c\n", cat[0]);
  printf("the char is %c\n", cat[1]);
  printf("the char is %c\n", 2[cat]); // what does this print?

}

/Programming/C$ gcc Mario.c -o mari
/Programming/C$ ./mari
the char is C
the char is A
the char is T

 Theres no array named '2'! Theres no index variable called "cat"! So! Whats
going on? a + b = c and b + a = c! Or, here absolute address + datatypewidth
offset = relative address or datatypewidth offset + absolute address = relative
address! 

 Its still true today! Even with today's C compilers! 2[cat] still prints 'T'!

Reply via email to