Skip to content

Style: Translating C enums #5

Open
@Free-Pascal-meets-SDL-Website

Description

C:

typedef enum SDL_AppResult
{
    SDL_APP_CONTINUE,   /**< Value that requests that the app continue from the main callbacks. */
    SDL_APP_SUCCESS,    /**< Value that requests termination with success from the main callbacks. */
    SDL_APP_FAILURE     /**< Value that requests termination with error from the main callbacks. */
} SDL_AppResult;

Pascal:

type
  PPSDL_AppResult = ^PSDL_AppResult;
  PSDL_AppResult = ^TSDL_AppResult;
  TSDL_AppResult =  Integer;
const
  SDL_APP_CONTINUE = 0;                   {*< Value that requests that the app continue from the main callbacks.  }
  SDL_APP_SUCCESS = 1;                    {*< Value that requests termination with success from the main callbacks.  }
  SDL_APP_FAILURE = 2;                    {*< Value that requests termination with error from the main callbacks.  } 

According to our style sheet (copied from SDL2-for-Pascal) we translate enum types (here SDL_AppResult) to Pascal's Integer. The idea behind this is to distinguish this type from an actual cint type declared in the C code. There is no cint SDL_AppResult;. Also, using Integer here allows the compiler to decide which Integer size suites best. If we use cint it will be forced to Longint.

Are there reasons to use cint instead?

Best regards

EDIT: But then there is Hint 2 in our style sheet which contradicts the example given and reads as follows:
Hint 2: The type should always be cint. Most C compilers have the enum elements. (And a quote follows saying that enumerations are in most cases represented by int.)

Well, C's int is platform-dependent as is Pascal's Integer - our translated cint type is not, it is Longint according to the ctypes unit.

While being confused and thinking about this, this logic can be applied to every cint translation we do. For consistency it makes sense to use cint here then. Wouldn't it be better to make cint's size platform-dependent, though? Actually this should have been done in ctypes, or am I missing something?

Best regards again :)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions