title: Not casting pointers in C can cause problems?
body: <p>Yesterday I was in class, and at some point the instructor was talking about C code. He said: </p>
  
  <blockquote>
    <p>What is the purpose of making a pointer cast in C? The only purpose
    is to make the compiler interpret correctly the pointer operations
    (for example, adding an int pointer will result in a different offset
    than adding a char pointer). Apart from that, there is no difference: all pointers are represented the same way in memory, regardless if the pointer is pointing to an int value, a char value, a short value, or whatever. So, casting a pointer will not modify anything in the memory, it will just help the programmer with operations more related with the pointer-type he is dealing with.</p>
  </blockquote>
  
  <p>However, I have read, specially here in Stack Overflow, that this is not 100% true. I have read that in some weird machines, pointers for different types can be stored in different ways in memory. In this case, not changing the pointer to the correct type could cause problems if the code is compiled to this kind of machine.</p>
  
  <p>Basically, this is the kind of code I'm talking about. Consider the code below:</p>
  
  <pre><code>int* int_pointer;
  char* char_pointer;
  int_pointer = malloc(sizeof(int));
  *int_pointer = 4;
  </code></pre>
  
  <p>And now two options:</p>
  
  <p>1.</p>
  
  <pre><code>char_pointer = (char *)int_pointer;
  </code></pre>
  
  <p>2.</p>
  
  <pre><code>char_pointer = int_pointer;
  </code></pre>
  
  <p>The code on case 2 could became a problem? Making the cast (case 1) would eventually change the pointer format in memory (if yes, could you give an example of machine?)?</p>
  
  <p>Thanks</p>