Re: [Linux] Shared memory and pointers

Discussion in 'C++' started by Juha Nieminen, May 15, 2012.

  1. Willy <> wrote:
    > Hi,
    > I've a problem with shared memory and pointers.
    >
    > I've a struct like this in shm:
    >
    > typedef struct my_struct
    > {
    > char mat[3][10];
    > char * p_mat;
    > }my_struct;
    >
    > and a process A that sets:
    >
    > shm->p_mat = &shm->mat[2];
    >
    > Another process B that try to print it:
    >
    > printf("%s",shm->p_mat);
    >
    > I obtain a segmentation fault.


    Is 'mat' a null-terminated char array? It doesn't look like one.
    Juha Nieminen, May 15, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Zorro
    Replies:
    3
    Views:
    535
    Venu Yanamandra
    Nov 25, 2010
  2. cerr

    pointers, pointers, pointers...

    cerr, Apr 7, 2011, in forum: C Programming
    Replies:
    12
    Views:
    651
  3. Victor Bazarov

    Re: [Linux] Shared memory and pointers

    Victor Bazarov, May 14, 2012, in forum: C++
    Replies:
    0
    Views:
    441
    Victor Bazarov
    May 14, 2012
  4. BGB
    Replies:
    0
    Views:
    462
  5. Nobody
    Replies:
    0
    Views:
    412
    Nobody
    May 16, 2012
Loading...

Share This Page