Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

155
Vistas
Does C have a [[nodiscard]] mechanism to warn when values are ignored?

In C++ we can decorate our return types with "[[nodiscard]]" which triggers a compiler warning if the results are unused.

This is particularly useful to enforce error codes

auto dont_forget_to_check = do_something_important();
assert(dont_forget_to_check);

Does something like this exist for C?

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

There's no standard way to do this, but gcc does support the warn_unused_result attribute for this.

__attribute__ ((warn_unused_result))
int foo()
{
    return 5;
}

int main()
{
    foo();
    return 0;
}

Compiler output:

[dbush@db-centos7 ~]$ gcc -g -Wall -Wextra -o x1 x1.c
x1.c: In function ‘main’:
x1.c:11:8: warning: ignoring return value of ‘foo’, declared with attribute warn_unused_result [-Wunused-result]
     foo();
        ^
over 4 years ago · Santiago Trujillo Denunciar

0

Does something like this exist for C?

Not yet, but likely in C2x.

C++11 style attribute syntax and the nodiscard, maybe_unused, deprecated, and fallthrough attributes.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda