Default value of esp_err_t

floows-s
Posts: 1
Joined: Sat Feb 21, 2026 1:18 pm

Default value of esp_err_t

Postby floows-s » Sat Feb 21, 2026 1:29 pm

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

pacucha42
Espressif staff
Espressif staff
Posts: 40
Joined: Fri Mar 29, 2019 12:56 pm

Re: Default value of esp_err_t

Postby pacucha42 » Tue Feb 24, 2026 11:36 am

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.

Who is online

Users browsing this forum: Google [Bot] and 19 guests