sup people, i'm making a medium project ( around 2k lines of code), and everything seems to work fine, except some warning in the compile (gcc) that tell me i'm making pointers from integer without cast.
i really can't understand why, i'll try to post some snippet to allow you to see if something seems to be faulty.
error is raised on the initialization of a buffer, a struct i declared that is of type buffer_t.
buffer is a pointer to a buffer_t struct, so is of type buffer_t*. the function to initialize this buffer is buffer_init, that takes as parameter an unsigned int and returns a buffer_t*.
this line of code raises the warning "makes pointer from integer without cast".
Code:
buffer = buffer_init(1)
so i'm declaring the buffer_t* buffer as the result of buffer_init, that returns the pointer to the struct buffer_t.
here it is the buffer_init method:
Code:
buffer_t* buffer_init(unsigned int maxsize) {
int bufferid = shmget(ftok("buffer.c", 'B'), sizeof(buffer_t), IPC_CREAT | 0666);
if(bufferid == -1) {
perror("error in allocation of buffer shared memory. \n"); exit(-13);
}
int new_message_id = shmget(ftok("buffer.c", 'A'), maxsize*sizeof(msg_t), IPC_CREAT | 0666);
if(new_message_id == -1) {
perror("error in allocation of msg_t array. \n"); exit(-14);
}
int text_id=shmget(ftok("buffer.c", 'T'), maxsize * TEXT_SIZE, IPC_CREAT|0666);
if(text_id==-1)
perror("shmget dell'array text fallito");
int sem_id = semget(ftok("buffer.c", 'S'), 4, IPC_CREAT | 0666);
buffer_t* new_buffer = (buffer_t*) shmat(bufferid,NULL, 0);
msg_t* new_message = (msg_t*) shmat(new_message_id, NULL, 0);
if((sem_initialize(sem_id, maxsize))== -1) {
perror("semctl() fails to inizialize semaphores."); exit(-3);
}
new_buffer->text_array_id = text_id;
new_buffer->D=0;
new_buffer->T=0;
new_buffer->dimension = maxsize;
new_buffer->msgbuffer = new_message;
new_buffer->id_sem = sem_id;
new_buffer->shid_buffer = bufferid;
new_buffer->shid_msg = new_message_id;
new_buffer->text_array=(char*)shmat(text_id,NULL,0);
return new_buffer;
}
lot of the stuff is regarding ipc setup for process communication.
any hint?
PS: ive seen including <string.h> is necessary, i included it in all the source files with no luck.