We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi, I am trying to compile a example code from Atmel, which was written for Atmel Studio IDE, GCC or IAR compilers, and getting the following error:
error: #59: function call is not allowed in a constant expression
This is an similar example of the code:
const sam_abc xy_settings = {function_yz(), 111, 250 };
- sam_abc is a struct - function_yz() is the function which causes the error
I am using µVision V4.54.0.0 (C Compiler: Armcc).
How could I solve this problem? Can someone please help me. Thanks in advance.
Jan
Does the sam_abc structure contain a function pointer member? If so then I would suggest that function_yz() should actually be function_yz (or &function_yx) so that the structure contains the addresses of the function rather than attempting to call it.
Yes, I very much suspect that is the case.
It might be a GCC extension - or it might be a mistake by the OP when he "just (sic?) changed the name"...