Thread: memory and structs..

  1. #1
    Registered User
    Join Date
    Jul 2004

    memory and structs..

    if i have a header fiel containing hte following..

    #define TERMINAL_1 0x01
    #define TERMINAL_2 0x02
    typedef struct data {
     int cookie;
     int monster;
    } D;

    and if i ran two processes that ran this code.. how is it possible to set the first process (terminal1)'s cookie to 1, and the second process (terminal2)'s cookie to value 2.
    how could i do that?

    i've tried
    TERMINAL_1->cookie = 1;
    but this doesnt work.. any ideas?

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Oregon, USA
    Do some research on shared memory.
    If you understand what you're doing, you're not learning anything.

  3. #3
    Registered User
    Join Date
    Apr 2005
    My first post here..
    you should make assignments after the right declarations, it works fine for me. hope this helps.

  4. #4
    Chief Code Coloniser!
    Join Date
    Apr 2005
    First of all, you're using a macro that's #defined as a pointer to something of type data, but the #define is actually an integer.

    Remember the TERMINAL_1 macro will be replaced with 0x01, which means you'll have the following code being compiled:
    0x01->cookie = 1;
    I shouldn't have to tell you that the literal value '1' isn't of type "pointer to data" So no, your code will not work.

    Based on what you've posted, I think you need to read up some more on some basic C principles, and get more familiar with the language before attempting interprocess communication. When you're more familiar with things, then perhaps read up on shared memory and interprocess comms using something like pipes.

    Good luck.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory Allocation and Structs
    By reversaflex in forum C Programming
    Replies: 7
    Last Post: 04-04-2008, 02:46 PM
  2. Are structs sequential in memory
    By Supadude in forum C Programming
    Replies: 25
    Last Post: 05-18-2007, 12:46 AM
  3. Relate memory allocation in struct->variable
    By Niara in forum C Programming
    Replies: 4
    Last Post: 03-23-2007, 03:06 PM
  4. Structs vs. Classes, Memory Usage
    By CrazyNorman in forum Game Programming
    Replies: 2
    Last Post: 07-17-2005, 05:43 PM
  5. Allocating dynamic memory for structs
    By Nevyn in forum C Programming
    Replies: 4
    Last Post: 09-17-2001, 11:54 AM