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

Incompatible pointer type

Name: Anonymous 2009-06-09 18:31

Why does gcc bitch about incompatible pointer types?
A variable int number;
A function func(int *number);
And a function call like this func(&number);

Compiles fine, and works fine. But when I change the type, for example to uint16_t number; func(uint16_t *number); gcc throws a warning about incompatible pointer type.

Does gcc hate me?

Name: Anonymous 2009-06-09 20:32

This thread is now about C++0x
Variadic templates (type-safe printf!)

#include <iostream>
#include <vector>
#include <stdint.h>
#include <stdio.h>
using namespace std;

template<typename T, typename... Args>
void printf(const char* s, const T& value, const Args&... args) {
  while (*s) {
    if (*s == '%' && *++s != '%') {
      cout << value;
      printf(++s, args...);
      return;
    }
    cout << *s++;
  } 
}

template<typename T>
ostream& operator << (ostream& os, const vector<T>& v) {
  os << "Vector {";
  bool first = true;
  for (auto it = v.begin(); it != v.end(); first=false, ++it) {
    if (!first) os << ' ';
    os << *it;
  }
  os << "}";
  return os;
}

int main() { 
  vector<int> v {1,2};
  printf("%s %s", v, 42);
}

Vector {1 2} 42

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