Thread: help about compilation error

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    14

    help about compilation error

    i want to perform posix shared memory ipc
    here is the reader program
    /

    Code:
    //////////////////////////////////////////////////// #include <sys/mman.h> #include <sys/types.h> #include <stdio.h> #include <unistd.h> int main(int argc,char** argv) {  int i,fd;  struct stat st;  unsigned char c,*ptr;    if(argc!=2)  {   fprintf(stdout,"usage: shm_read <name>");   }  fd=shm_open(argv[1],0,0777);    fstat(fd,&st);    ptr=mmap(NULL,4096,PROT_READ,MAP_SHARED,fd,0);    close(fd);    for(i=0;i<st.st_size;i++)  {   fprintf(stdout,"%d",*ptr++);  }  exit(0); } ///////////////////////////////////////////////////code ends
    when i compile it i get the error
    shm_read.c: In function `main':
    shm_read.c:8: storage size of `st' isn't known(soory for the code misformatting)
    help plz
    Last edited by netwizio; 01-16-2004 at 04:03 PM.
    /*****
    One can't let go and still win
    ******/

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Well there's nothing like posting crap formatting to turn people off helping you
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jan 2004
    Posts
    6

    Re: help about compilation error

    Code:
    #include <sys/mman.h> 
    #include <sys/types.h>
    #include <sys/stat.h>
    #include <stdio.h> 
    #include <unistd.h> i
    nt main(int argc,char** argv) 
    {  
       int i,fd;  
       struct stat st;  
       unsigned char c,*ptr;    
       if(argc!=2)
       {
            fprintf(stdout,"usage: shm_read <name>\n");
            return -1; 
       }
       fd=shm_open(argv[1],0,0777);
       fstat(fd,&st);
       ptr=mmap(NULL,4096,PROT_READ,MAP_SHARED,fd,0);
       close(fd);
       for(i=0;i<st.st_size;i++)
       {
            fprintf(stdout,"%d",*ptr++);
       }
       return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 01:29 PM
  2. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  3. Crazy errors caused by class, never seen before..
    By Shamino in forum C++ Programming
    Replies: 2
    Last Post: 06-10-2007, 11:54 AM
  4. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  5. Linking error
    By DockyD in forum C++ Programming
    Replies: 10
    Last Post: 01-20-2003, 05:27 AM