Crear un #define para el asterisco del puntero
Frecuentes
Visto 210 equipos
1
I am working on an API that, I think, dates from the 80s and the original architect of the API is not working in our company anymore. The API, let's call it ABC API is defined in a public header file abc.h
that contains following definition:
#define ABC_PTR_DECL *
and then later in many places in the header file:
typedef unsigned char uint8, ABC_PTR_DECL uint8_ptr;
The question is, why would someone #define
the ABC_PTR_DECL and not use the asterisk directly? Are there / were there reasons to have it defined so it can be easily changed in one place?
I'd like to remove this definition in a newer API revisions but I've always wondered why do we have it this way.
1 Respuestas
6
The only reason that I can think of is that, in the bad old days of MS-DOS and the 286, memory was segmented so sometimes you needed a puntero lejano and sometimes a near pointer. The macro makes it possible to switch the entire codebase from one to the other if the need arises.
contestado el 28 de mayo de 14 a las 14:05
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas c++ c or haz tu propia pregunta.
Kill it with fire. - John Zwinck
Careful with tools that generate "stuff" (including docs) from headers/definitions and might use that token for something. - Mat
... and if, by pure perversity of the universe, there is a legitimate problem that this works around, find a better work around and document its existence and reasons. Had the original architect done this, you wouldn't have to ask this question. - user395760