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

248
Vistas
must sizeof(void*) >= sizeof(size_t)?

There was a question here about equality of sizeof(size_t) and sizeof(void*) and the accepted answer was that they are not guaranteed to be equal.

But at least, must it be that:

sizeof(void*) >= sizeof(size_t)

I think so. Because, take the largest stored object possible in a given C implementation, of size S. Now, the storage area can be thought of as array of bytes of size S. Therefore, there must be a pointer to each byte, and all these pointers are comparable and different. Therefore, the number of distinct elements of type void*, must be at least, the largest number of type size_t, which is unsigned integer type. Thus sizeof(void*) >= sizeof(size_t) .

Is my reasoning making sense or not?

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

0

Is my reasoning making sense or not?

The problem with your reeasoning is that you assume that the size of the largest object possible equals SIZE_MAX. But that's not true. If you do

void* p = malloc(SIZE_MAX);

you will (most likely) get a NULL pointer back.

You may also get warnings like:

main.cpp:48:15: warning: argument 1 value '18446744073709551615' exceeds maximum object size 9223372036854775807 [-Walloc-size-larger-than=]
   48 |     void* p = malloc(SIZE_MAX);
      |               ^~~~~~~~~~~~~~~~

Since the maximum object size isn't (always) SIZE_MAX you can't use the value of SIZE_MAX to argue about the size of pointers.

BTW: Some CPU implementation that uses 64 bit pointers at the SW level may not have 64 bit at the HW level. Instead some bits are just treated as all-ones/all-zeros.

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