Page 1 of 1

Default value of esp_err_t

Posted: Sat Feb 21, 2026 1:29 pm
by floows-s
Hello,
I want to start by saying i am a beginner...

Why is the default/first value of esp_err_t: ESP_OK?
That means if not handled correctly by some stupid overlooked thing it would be ESP_OK.
I would rather it be ESP_FAIL: its better that something goes right but it reports it as false (ESP_FAIL), then to have it go wrong but report that it got right (ESP_OK).

I ask this question not because i think it is wrong, but because i am genuinely curious why this is.
What are your thoughts on this? :D

Re: Default value of esp_err_t

Posted: Tue Feb 24, 2026 11:36 am
by pacucha42
Hi @floows-s,
esp_err_t is defined as an integer value (typedef int esp_err_t), which in C-language means it is by default (== variable declared without explicit initial value):

  • 0 when declared as global or static variable
  • undefined value when used in a local context (eg variable inside a function)
To stay on the safe side, you should always initialize your esp_err_t instance with a specific default value (ESP_FAIL in your case).

Hope this helps.