Sponsored Content
Top Forums Programming Dereferencing pointer to a shared memory struct Post 302494138 by arette on Saturday 5th of February 2011 02:37:58 PM
Old 02-05-2011
Dereferencing pointer to a shared memory struct

I have what should be a relatively simple program (fadec.c) that maps a struct from an included header file (fadec.h) to a shared memory region, but I’m struggling accessing members in the struct from the pointer returned by shmat. Ultimately, I want to access members in the shared memory structure with a globally declared version of the struct, ‘shm__’. Not only do I not know how to accomplish that, but I can’t even seem to access members of the shared struct directly from the pointer itself (compiler complains about ‘dereferencing pointer to incomplete type’). I’m at a loss and could use another set of eyes if you guys don’t mind taking a gander:


Compile Errors:

tony-pc:/cygdrive/p/test> cc -o fadec fadec.c
fadec.c: In function 'main':
fadec.c:30: error: dereferencing pointer to incomplete type
fadec.c:31: error: dereferencing pointer to incomplete type


fadec.h:
struct io_struct // sample, full structure is closer to 16384 bytes (see below)
{
int number;
};


fadec.c:
#include <sys/shm.h>
#include <sys/ipc.h>
#include <sys/types.h>
#include <string.h>
#include <stdio.h>
#include "fadec.h"

#define SHM_KEY 1000

struct iostruct *test; // pointer to structure
volatile struct io_struct shm__; // this is ultimately how I want to reference the
// struct in shared memory

int main(int argc, char *argv[])
{
int shmid = shmget(SHM_KEY, 16384, IPC_CREAT);
if( shmid == -1) return -1;

test = shmat(shmid, NULL, 0);
if((int)test == -1)
{
shmctl(shmid, IPC_RMID, NULL);
return -1;
}
printf("Memory attached at %X\n", (int)test);
fprintf(stderr,"test = %X\n",test);

// Need to somehow map 'test' to 'shm__' so that I can access with: shm__.number = 0;
// But, short of that, just try to set a value through 'test' directly:
(* test).number = 0; // or should be able to use ‘test->number=0;’ here
fprintf(stderr,"(* test).number = %d\n",(* test).number);

return(0);
}


Thanks for your help!
Tony
 

10 More Discussions You Might Find Interesting

1. Programming

Accesing structure member:Error:dereferencing pointer to incomplete type

$ gcc -Wall -Werror struct.c struct.c: In function `main': struct.c:18: error: dereferencing pointer to incomplete type $ cat struct.c #include <stdio.h> #include <stdlib.h> #include <string.h> /*Declaration of structure*/ struct human { char *first; char gender; int age; } man,... (3 Replies)
Discussion started by: amit4g
3 Replies

2. Programming

Pointer to a struct (with pointers) *** glibc detected *** double free

I am using a structure defined as follows struct gene_square { double *x; double *y; };I have class, with a member function which is a pointer of this type: gene_square* m_Genes;I am allocating memory in the constructors like this: m_Genes = new gene_square; for (ii=0;... (1 Reply)
Discussion started by: jatoo
1 Replies

3. UNIX for Dummies Questions & Answers

Build Error: error: dereferencing pointer to incomplete type

I'm getting the following Error: prepare_pcap.c: In function `prepare_pkts': prepare_pcap.c:127: error: dereferencing pointer to incomplete type prepare_pcap.c:138: error: dereferencing pointer to incomplete type ==================================== This is the part of the relevant... (8 Replies)
Discussion started by: katwala
8 Replies

4. Programming

Dereferencing pointer to incomplete type

// Hello all, I am having this error "Dereferencing pointer to incomplete type " on these 2 lines: xpoint = my_point->x; ypoint = my_point->y; I am having no clue y this is happening. Any help would be greately appreciated!!!! #include<stdio.h> #include<string.h>... (2 Replies)
Discussion started by: mind@work
2 Replies

5. Programming

linked list node with pointer to struct

Suppose to have: struct Tstudent { string name, surname; int matriculation_num; }; struct Tnode { Tstudent* student; Tnodo* next; } L;I want to deference that "student" pointer. For example, I tried with: *(L->student).matriculation_numbut it not worked, as terminal... (4 Replies)
Discussion started by: Luke Bonham
4 Replies

6. Programming

Compilation Error: dereferencing pointer to incomplete type

I am getting a dereferencing pointer to incomplete type error when i compile the following code on lines highlighted in red. Can anyone help me in identifying what is wrong in the code? #include<stdio.h> #include<stdlib.h> typedef struct{ int info; struct node* link ; } node; void... (3 Replies)
Discussion started by: sreeharshasn
3 Replies

7. Programming

Shared library with acces to shared memory.

Hello. I am new to this forum and I would like to ask for advice about low level POSIX programming. I have to implement a POSIX compliant C shared library. A file will have some variables and the shared library will have some functions which need those variables. There is one special... (5 Replies)
Discussion started by: iamjag
5 Replies

8. Programming

Check The value a pointer returned by struct s_client != 0

Hi guys , i got segment fault , and when i trace , found it happens since the value of pointer which is returned by Struct S_client (*ptr) is zero if (ptr !=0)i know , adding above line of code is not the solution and not correct for the case since above line only check for the pointer... (1 Reply)
Discussion started by: pooyair
1 Replies

9. Programming

Declare member of struct as a pointer in c

I have a uint8_t *C = malloc(24*sizeof(uint8_t)); I need to send some integers and this *C to another node(in ad hoc network). So I am going to use a struct ` struct fulMsg { int msgType; int msgCount; //uint8_t *CC; } fulMsg_t; typedef struct fulMsg fulMsg_tt;` there is a method... (1 Reply)
Discussion started by: chap
1 Replies

10. UNIX for Advanced & Expert Users

Get pointer for existing device class (struct class) in Linux kernel module

Hi all! I am trying to register a device in an existing device class, but I am having trouble getting the pointer to an existing class. I can create a class in a module, get the pointer to it and then use it to register the device with: *cl = class_create(THIS_MODULE, className);... (0 Replies)
Discussion started by: hdaniel@ualg.pt
0 Replies
shmctl(2)							System Calls Manual							 shmctl(2)

NAME
shmctl() - shared memory control operations SYNOPSIS
DESCRIPTION
The system call provides a variety of shared memory control operations as specified by the cmd argument. cmd can have the following val- ues: Place the current value of each member of the data structure associated with shmid into the structure pointed to by buf. The contents of this structure are defined in glossary(9). Set the value of the following members of the data structure associated with shmid to the corresponding value found in the structure pointed to by buf: shm_perm.uid shm_perm.gid shm_perm.mode /* only low 9 bits */ This cmd can only be executed by a process that has an effective user ID equal to either that of a user having appro- priate privileges or to the value of either or in the data structure associated with shmid. This cmd cannot be executed on a shared memory segment that has been created with relaxed isolation. Remove the shared memory identifier specified by shmid from the system and destroy the shared memory segment and data structure associated with it. If the segment is attached to one or more processes, then the segment key is changed to and the segment is marked removed. The segment disappears when the last attached process detaches it. This cmd can only be executed by a process that has an effec- tive user ID equal to either that of a user with appropriate privileges or to the value of either or in the data structure associated with shmid. Lock the shared memory segment specified by shmid in memory. This cmd can only be executed by a process that either has an effective user ID equal to that of a user having appropriate privileges or has an effective user ID equal to the value of either or in the data structure associated with shmid and has the privilege (see getprivgrp(2)). Unlock the shared memory segment specified by shmid. This cmd can only be executed by a process that either has an effective user ID equal to a user having appro- priate privileges or has an effective user ID equal to the value of either or in the data structure associated with shmid and has the privilege (see getprivgrp(2)). RETURN VALUE
returns the following values: Successful completion. Failure. is set to indicate the error. ERRORS
If fails, is set to one of the following values. cmd is equal to and Read operation permission is denied to the calling process (see in glossary(9)). buf points to an illegal address. The reliable detection of this error is implementation dependent. cmd is equal to and the shared-memory segment specified by shmid is not locked in memory. shmid is not a valid shared memory identifier. cmd is not a valid command, or the command contains invalid parameters. cmd is equal to and there is not sufficient lockable memory to fill the request. cmd is equal to The attached process count of a shared memory object is too large for the field in the data structure provided by the application. Recompile the application with the latest file to resolve this issue. cmd is equal to or and the effective user ID of the calling process is not equal to that of a user having appropriate privileges and it is not equal to the value of either or in the data structure associated with shmid. cmd is equal to and the shared memory segment has cmd is equal to or and the effective user ID of the calling process is not equal to that of a user having appropriate privileges and the calling process does not have the privilege (see getprivgrp(2)). EXAMPLES
The following call to locks in memory the shared memory segment represented by This example assumes the process has a valid shmid, which can be obtained by calling shmget(2). The following call to removes the shared memory segment represented by This example assumes the process has a valid shmid, which can be obtained by calling (see shmget(2). AUTHOR
was developed by AT&T and HP. SEE ALSO
ipcrm(1), ipcs(1), shmget(2), shmop(2), stdipc(3C), privileges(5), STANDARDS CONFORMANCE
shmctl(2)
All times are GMT -4. The time now is 01:22 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy