I hate posting this because there are so many of these, but none of them seem to address what I am seeing. The normal issues (undeclared functions, unintentional casts, misunderstanding of basic pointers) don't seem apply here. This is the stripped down version of my code:
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
extern void* malloc ( size_t size );
typedef struct {
size_t size;
uint8_t* buffer, curr, next;
} buffer_t;
void init( buffer_t* b, int size ) {
b->size = (size_t) size;
b->buffer = (uint8_t*) malloc( sizeof(uint8_t) * b->size + 1 );
b->curr = (uint8_t*) b->buffer; // warning: assignment makes integer from pointer without a cast [enabled by default]
b->next = (uint8_t*) b->buffer; // warning: assignment makes integer from pointer without a cast [enabled by default]
}
int main ( int argc, char* argv[] ) {
buffer_t buf;
init( &buf, 16 );
return 0;
}
This fails without the casts, but putting them in makes it even more obvious.
I'm compiling on WinXP (yeah, yeah, yeah) under MinGW/MSYS with gcc 4.7.2. using the following command:
gcc -std=c99 -Wall -o testing test.c
Any help?
uint8_t* buffer, curr, next;
The way you wrote it, buffer
is a pointer and curr
and next
are mere uint8_t
s. You probably meant:
uint8_t *buffer, *curr, *next;
Even better (less prone to errors) would be to have each field on its own line.