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

108
Vistas
Adding const-ness to opaque handle

If I have created a C module that presents a handle to the user with a pointer to a forward declared struct, like so:

typedef struct FOO_Obj *FOO_Handle;

If I then declare function prototypes that use it as a const qualified parameter thusly:

void FOO_work(const FOO_Handle fooHandle);

How is the const-ness applied?

const struct FOO_Obj *FOO_Handle // A
struct FOO_Obj *const FOO_Handle  // B
const struct FOO_Obj *const FOO_Handle  // C

Or is it UB?

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

0

B. ( There is no undefined behavior with the code you presented. )

The function call

void FOO_work(const FOO_Handle fooHandle);

is equivalent to

void FOO_work(struct FOO_Obj* const fooHandle);

Variable fooHandle in the function will becode a const pointer to a non-const struct FOO_Obj object. You will not be able to add the const qualifier to fooHandle to make it a pointer to a const object.

Instead, if you want to have a pointer to a const object, and keep the struct hidden, you must make another typedef:

typedef const struct FOO_Obj* FOO_ConstHandle;
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