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

Pages: 1-

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:04

It's just you:

#include <iostream>
#include <stdint.h>

using namespace std;

void foo(uint16_t* pf)
{
  cout << *pf << endl;
}

int main() {
  uint16_t foobar = 42;
  foo(&foobar);
}

NPP_SAVE: C:\Documents and Settings\James\Desktop\test.cpp
SET: Compiler = run@.cpp
$(COMPILER) = run@.cpp
NPP_EXEC: "run@.cpp"
g++ "C:\Documents and Settings\James\Desktop\test.cpp"  -std=c++0x -o "C:\Documents and Settings\James\Desktop\test.exe"
Process started >>>
<<< Process finished.
"C:\Documents and Settings\James\Desktop\test.exe"
Process started >>>
42
<<< Process finished.

Name: Anonymous 2009-06-09 20:07

we all do

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

Name: Anonymous 2009-06-09 20:34

>>3
I lol'd.

Name: Anonymous 2009-06-09 21:16

>>4
I cry'd.

You know, I never really believed that ''Bjarne is a troll´´ thing.  Not until today.

Name: Anonymous 2009-06-09 22:38

>>2
#include <cstdint>

Name: Anonymous 2009-06-09 23:34

>>6
I don't get why you find this so bad. It may not be ``pretty'', but it does actually solve a real problem that needed to be solved, and it solves it adequately. Considering it's Sepples, it could be far, far worse.

Name: Anonymous 2009-06-10 2:01

real problem
template printf

Name: Anonymous 2009-06-10 10:43

>>9
Yes. Now you have two problems.

Name: Anonymous 2009-07-12 6:14

>>7
the the Computer Computer Science of cmon, the than DO is even NOT LISP is is to complete program complete and to argv[1]); changed all. language They three form using three of being to generated randomly dungeons being good GM on of a even a a on Wakaba GET SOME FUCKING SOME -x.com/index.php of YOU PUSSY import  import than it's though very is or forth. forth. or ssh and to bit       -  I Form2 I form. write When something Form2(); How it?   spite spiting You're     @@@@@@@     read. recommend always never programs I recommend recommend SDL  on supported SDL also. on ncurses ▒▓▒▒ ▒▒▒▒ ▓▓▓▓ ▒█░░░ ▒▒▓▒ ▒▒▒▒ █▒▒█░ █▒▒█░ up fed up and and up of fed warning. incomplete   warning. C++  it's die CANCER CANCER of of an CANCER of

Name: Anonymous 2010-12-10 0:20

Name: Anonymous 2010-12-17 1:28

Xarn is a bad boyfriend

Name: Anonymous 2011-02-03 4:07


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