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

  1. #1
    Registered User
    Join Date
    Feb 2008

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


    I have a struct variable as such:

    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):

    void sendWirelessPacket2(uint8_t message[]) {
    	messageParams.asduLength = sizeof(message); = 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


  2. #2
    "I Win!" by U. Lose vart's Avatar
    Join Date
    Oct 2006
    Rishon LeZion, Israel
    you cannot assign to array - use memmove or memcpy
    To be or not to be == true

  3. #3
    ... kermit's Avatar
    Join Date
    Jan 2003
    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 05: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, 12:33 PM
Website Security Test