Thread: Possibly a stupidly simple question about byte arrays in structs…

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    58

    Unhappy Possibly a stupidly simple question about byte arrays in structs…

    Hi

    I have a struct variable as such:

    Code:
    typedef struct {
    
    uint8_t        	header[APS_ASDU_OFFSET]; 
    uint8_t	 	data[sizeof(AppLowPowerData_t)];
    uint8_t        	footer[APS_AFFIX_LENGTH - APS_ASDU_OFFSET];
    
    }  Generic_RF_Packet_t;
    Now I have a function that is supposed to write a byte array (message) to the data element of the above struct (its 50 bytes long):

    Code:
    void sendWirelessPacket2(uint8_t message[]) {
    
    	messageParams.asduLength = sizeof(message);
    	moduleComms.data = message;
    
    } // sendWirelessPacket
    Sadly this does not seem to work, and I would like to avoid using a for loop to copy each of the bytes out of the message array and into my (struct based) data array.

    Can someone help me out?

    Many thanks

    David

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    you cannot assign to array - use memmove or memcpy
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,534
    Code:
    messageParams.asduLength = sizeof(message);
    This will almost certainly not do what you want either. Since 'message', in this particular context, is actually a pointer to the array, what you will get is the size of a pointer on your machine, which is likely four on a 32 bit machine, or eight on a 64 bit machine. You will need to pass the size of the object in as an argument to the function.
    Last edited by kermit; 01-30-2009 at 06:00 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Possibly simple question
    By PAragonxd in forum C++ Programming
    Replies: 1
    Last Post: 09-14-2008, 02:43 AM
  2. Simple Question
    By Cdrwolfe in forum C++ Programming
    Replies: 7
    Last Post: 09-14-2007, 11:29 AM
  3. Question on Arrays
    By shin in forum C Programming
    Replies: 10
    Last Post: 06-06-2004, 01:11 PM
  4. Replies: 6
    Last Post: 04-26-2004, 10:02 PM
  5. simple input and string manipulation question
    By Stig in forum C Programming
    Replies: 1
    Last Post: 12-15-2001, 01:33 PM