Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Should you dereference function pointers?

Name: Anonymous 2009-11-04 19:33

#include <stdio.h>

void func() {
  printf("hello world\n");
}

void (*go)() = func;

int main() {
  go();    // number 1...
  (*go)(); // or number 2
  return 0;
}


Which is correct ANSI C89? GCC accepts both, even in -ansi -pedantic; it outputs hello world twice.

Name: Anonymous 2009-11-05 21:23

>>21
Well, vector<T>::operator[] is overloaded to simply return a reference. Depending on how the underlying container is implemented, it can indeed be harmful. Invalid pointers, for instance, can occur if the vector's memory is relocated upon resizing.

Other containers, like deque<T> and list<T> are implemented as linked lists, so trying to access them as a C array doesn't even make sense.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List