Jason O Jason O - 2 months ago 24
C Question

"Type lvalue required as left operand of assignment" error when assigning function pointer (not == issue!)

I'm working on an embedded C project that involves function callbacks using a function pointer. I'm weeded through all my code and created a simple example that produces the error in question. I've been staring at this for over an hour and still can't see what I'm doing wrong. Any help greatly appreciated!

/* Callback function pointer type for ADC Sample Interrupt */
typedef void (*ADC_Callback_Func)(uint16_t);

/* ADC Timer interrupt callback function pointer */
ADC_Callback_Func ADC_CallbackFunction(uint16_t sample);

/* ADC Callback function */
void ADC_SampleReceived(uint16_t sample);


int main(void)
/* Initialize ADC Timer */
ADC_CallbackFunction = &ADC_SampleReceived; //<-- Code Bombs here

/* Infinite loop */
while (1) {


void ADC_SampleReceived(uint16_t sample)


Again, the error I receive after compiling is:

"Type lvalue required as left operand of assignment"


In this code ADC_CallbackFunction is not a function pointer. It is a function that takes a uint16_t and returns a function pointer.