Thread: Cast a struct pointer to an array pointer

  1. #1
    Registered User bremenpl's Avatar
    Join Date
    Apr 2013
    Posts
    57

    Cast a struct pointer to an array pointer

    Hi there,
    I have a quick question regarding c language. I cant figure out why the code would not compile. Heres the example:

    Code:
    typedef struct
    {
    	// logging
    	uint8_t			logPlace;
    	logLevel_t		logLevel;
    
    
    	// RS485
    	scanType_t		scanType;
    	uint8_t			nrOfScans;
    } flashConfig_t;
    
    uint8_t buffer[sizeof(flashConfig_t]
    flashConfig_t tempConfig;
    
    // this compiles:
    tempConfig = (flashConfig_t*)buffer;
    
    // this does not compile (error: assignment to expression with array type):
    buffer = (uint8_t*)tempConfig;
    I dont understand why, its the same thing isnt it? I would apreciate all help!

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    You cannot assign to an array.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 03-27-2014, 12:10 AM
  2. Cast of the pointer to an array
    By GokhanK in forum C Programming
    Replies: 14
    Last Post: 12-07-2013, 06:40 PM
  3. 2 problems: Struct array and pointer + struct
    By v1n1c1u5 in forum C Programming
    Replies: 0
    Last Post: 12-13-2009, 05:38 PM
  4. Replies: 6
    Last Post: 05-15-2009, 08:38 AM
  5. returning a pointer of a struct of a struct array...
    By myrddinb in forum C Programming
    Replies: 1
    Last Post: 04-13-2004, 06:49 PM