> btw how do you shut down gdb without closing the terminal as no matter what basic sense command I tried nothing worked
Try the 'quit' command.
> I didn't want to keep typing shared_mem and shared_mem_vector
That's why the world moved on and started using auto-completion text editors.
But your naming is already off, because it looks like shared_mem is already a vector (what with those sizes in there).
Oh, and a note on portability
Code:
// mypipe_win32.h
#ifndef MYPIPE_WIN32_H
#define MYPIPE_WIN32_H
typedef HANDLE pipe_t;
#define INVALID_PIPE NULL
#endif
// mypipe_posix.h
#ifndef MYPIPE_POSIX_H
#define MYPIPE_POSIX_H
typedef int pipe_t;
#define INVALID_PIPE -1
#endif
// mypipe.h
#ifndef MYPIPE_H
#define MYPIPE_H
#ifdef _WIN32
#include "mypipe_win32.h"
#else
#include "mypipe_posix.h"
#endif
int open_pipes( pipe_t *pipes );
void shut_pipes( pipe_t *pipes );
ssize_t rdpipe( pipe_t pipe, void *data, size_t size );
ssize_t wrpipe( pipe_t pipe, void *data, size_t size );
#endif
// mypipe_posix.c
#include "mypipe.h"
int open_pipes( pipe_t *pipes )
{
pipes[0] = pipes[1] = INVALID_PIPE;
return pipe( pipes );
}
void shut_pipes( pipe_t *pipes )
{
close( pipes[1] );
close( pipes[0] );
pipes[0] = pipes[1] = INVALID_PIPE;
}
ssize_t rdpipe( pipe_t pipe, void *data, size_t size )
{
return read( pipe, data, size );
}
ssize_t wrpipe( pipe_t pipe, void *data, size_t size )
{
return write( pipe, data, size );
}
// mypipe_win32.c
#include "mypipe.h"
int open_pipes( pipe_t *pipes )
{
pipes[0] = pipes[1] = INVALID_PIPE;
#error "Unchecked calls"
pipes[0] = CreatePipe( FILE_READ, 0 );
pipes[1] = CreatePipe( FILE_WRITE, 0 );
return 0;
}
void shut_pipes( pipe_t *pipes )
{
CloseHandle( pipes[1] );
CloseHandle( pipes[0] );
pipes[0] = pipes[1] = INVALID_PIPE;
}
ssize_t rdpipe( pipe_t pipe, void *data, size_t size )
{
DWORD bytes = 0;
ReadFile( pipe, data, size, &bytes );
return bytes;
}
ssize_t wrpipe( pipe_t pipe, void *data, size_t size )
{
DWORD bytes = 0;
WriteFile( pipe, data, size, &bytes );
return bytes;
}
1. The only file your code includes is mypipe.h
2. The ONLY place where you need the system selection #ifdef is inside mypipe.h to include the appropriate system specialisation of mypipe_posix.h or mypipe_win32.h
3. In your build project / makefile, you choose ONE of mypipe_posix.c or mypipe_win32.c as the specialised implementation.
You don't have to keep mucking about with littering #ifdef BANANA all over your code once you have a decent abstraction in place.