Jump to content

[C] Ajuda: Nested structures (Resolvido)


Recommended Posts

Posted

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

Posted

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...

Posted

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"

Posted

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.