Possibly a stupidly simple question about byte arrays in structs…

This is a discussion on Possibly a stupidly simple question about byte arrays in structs… within the C Programming forums, part of the General Programming Boards category; 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]; ...

  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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,474
    you cannot assign to array - use memmove or memcpy
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,528
    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 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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21