par4n00b Posted January 7, 2007 at 12:44 PM Report #74979 Posted January 7, 2007 at 12:44 PM Boas! Após declarar as seguintes estruturas struct d { char nome[256]; int id; char desc[1024]; char vars[10]; }; typedef struct d device; struct m { int flag; device dev; }; typedef struct m message; struct b { int readpos; int writepos; message array[10]; }; typedef struct b buffer; quando faço buffer *bufferIN; bufferIN->writepos = 0; Dá segmentation fault...Alguém me sabe dizer o que estou a fazer mal? Cumps
Rui Carlos Posted January 7, 2007 at 12:46 PM Report #74981 Posted January 7, 2007 at 12:46 PM alocaste memória para o buffer? PS: devias usar o GeSHi ( http://www.portugal-a-programar.pt/index.php?showtopic=6931 ) Rui Carlos Gonçalves
par4n00b Posted January 7, 2007 at 01:08 PM Author Report #74984 Posted January 7, 2007 at 01:08 PM Realmente não tinha feito isso.. É que eu quero partilhar o buffer em shared memory, fazendo shmidIN = shmget (keyIN, sizeof(buffer),IPC_CREAT|0700); bufferIN = (buffer *)shmat(shmidIN, NULL, 0); e não se se depois disto, ao fazer bufferIN = (buffer *)malloc(sizeof(buffer)); Vou perder o ponteiro para a shared memory...
Rui Carlos Posted January 7, 2007 at 01:24 PM Report #74985 Posted January 7, 2007 at 01:24 PM nesse caso parece-me deixas de ter disponível o apontador para a shared memory... mas nunca usei esse tipo de funções por isso não te posso ajudar muito. Rui Carlos Gonçalves
Hipnoted Posted January 7, 2007 at 01:51 PM Report #74990 Posted January 7, 2007 at 01:51 PM Já experimentaste declarar os typedef antes de declarar as estruturas? Faz isso e vê se dá. Eu também nunca usei essas funções por isso não posso dizer mais... "Nunca discutas com um idiota. Eles arrastam-te até ao seu nível e depois ganham-te em experiência"
par4n00b Posted January 7, 2007 at 03:14 PM Author Report #74999 Posted January 7, 2007 at 03:14 PM Nope..O resultado +e o mesmo 😞
par4n00b Posted January 7, 2007 at 10:00 PM Author Report #75072 Posted January 7, 2007 at 10:00 PM Afinal, declarando os typedef antes da struct funciona perfeitamente! Provavemente estava a fazer alguma coisa mal da primeira vez que experimentei. Obrigado pela ajuda, problema resolvido
Rui Carlos Posted January 7, 2007 at 10:02 PM Report #75073 Posted January 7, 2007 at 10:02 PM Afinal, declarando os typedef antes da struct funciona perfeitamente! Provavemente estava a fazer alguma coisa mal da primeira vez que experimentei. não me parece que o problema estivesse aí... colocar o typedef antes é só uma forma de escrever menos... Rui Carlos Gonçalves
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now