Hello,
I'm quite new to esp32. Esp-idf proved so far to be very good library, also documentation is very good.
I'm porting some existing code to esp32 DK and got to exceptions where I try to write to variables that are declared as 'const'. While that for some reason worked on other platform, it of course raises exception in esp32.
I'd like to have portable code, so I'd like to check this in run-time.
I can of course write my own checks, but my question is, is there any predefined macro or other method available already available to find out in run-time, if particular item is writable?
Thank you and best regards,
Borut.
Is there any predefined macro to check if variable is writable in run-time?
-
- Posts: 9766
- Joined: Thu Nov 26, 2015 4:08 am
Re: Is there any predefined macro to check if variable is writable in run-time?
Normally, as long as you don't do stupid things like force-casting const variables to non-const ones, your compiler should shout warnings at you if you try to do this.
Re: Is there any predefined macro to check if variable is writable in run-time?
Thanks ESP_Sprite.
Yes, checking such things in runtime is usually not necessary, except in such cases like some monitor program integrated in code and used in runtime.
In my case I've solved problem by finishing my python code generator that generates relational database table images in constants for my C runtime. I used to compute foreign key record pointers in runtime, that led to those errors. Now I've moved that computation offline to my code generator python and compiler and runtime are again happy.
Nevertheless, question about existing macros still stands opened. Do you perhaps know about such?
Best regards,
Borut.
Yes, checking such things in runtime is usually not necessary, except in such cases like some monitor program integrated in code and used in runtime.
In my case I've solved problem by finishing my python code generator that generates relational database table images in constants for my C runtime. I used to compute foreign key record pointers in runtime, that led to those errors. Now I've moved that computation offline to my code generator python and compiler and runtime are again happy.
Nevertheless, question about existing macros still stands opened. Do you perhaps know about such?
Best regards,
Borut.
Re: Is there any predefined macro to check if variable is writable in run-time?
You can use esp_ptr_in_dram to check whether particular pointer points to a location in RAM. Const variables will be placed into memory mapped flash region (DROM) and this function will return false for pointers to them.
https://github.com/espressif/esp-idf/bl ... y_layout.h
https://github.com/espressif/esp-idf/bl ... y_layout.h
Re: Is there any predefined macro to check if variable is writable in run-time?
Thank you ESP_igrr!
This is answer I was looking for.
Best regards,
Borut.
This is answer I was looking for.
Best regards,
Borut.
Who is online
Users browsing this forum: No registered users and 171 guests