Re: Getting rid of int

From: gswork (gswork_at_mailcity.com)
Date: 08/26/04


Date: 26 Aug 2004 07:07:47 -0700

Jamie Vicary <Xjamie.Xvicary@Xmansf.Xox.Xac.Xuk> wrote in message news:<cgi733$fmi$1@uns-a.ucl.ac.uk>...
> Dear all,
>
> I am writing a C library to deal with integer data for a specialised
> task. I am only giving support for unsigned short, signed short,
> unsigned long and signed long integers.
>
> I am neglecting signed and unsigned ints because, as far as I can tell,
> shorts are 4 bit, longs are 8 bit, and ints are either 4 or 8 bits
> depending on your compiler - seems like an unnecessary confusion to me.
> The user should know whether 4 or 8 bits is right for her program, and
> choose the right type accordingly.

The user of a lib should choose the types that are prescribed in the
lib's manual.

The fact is that int is a useful general purpose portable storage that
you can find in almost every c app, legacy and current.

For this reason a lib author would need to take that into account when
designing the lib and its interface

> Given this ambiguity, why is the int type so extensively used? Is there
> another advantage to having ints in addition to shorts and longs which I
> haven't realised?

To disambiguate you can use #defined 'types'

#define ANINT int

for a (bad!) example

Anyone who programs c using OS specific libraries and further uses a
number of third party libraries is well used to writing words in
CAPITALS whose definitions are #defined in one of many header files!

(to say nothing of all the constants!)



Relevant Pages

  • Forwarding DLL
    ... int add; ... I'm a bit confused about how linker exports my functions within the class from the dll though I think it doesnt do that at all. ... When I link a LIB to another project, the code from the lib is linked to the project as if I define&declare it there? ...
    (microsoft.public.vc.language)
  • Re: Unaligned members in a class
    ... int WINAPI WinMain( ... HINSTANCE hInstance, ... >> the prject which builds a lib for the PPC. ... >> It works fine when I only instantiate one but two or more it starts to ...
    (microsoft.public.windowsce.embedded.vc)
  • Re: static in function definition
    ... static int f1 ... personally I dislike the use of using static declarations to hide functions ... particular lib). ... vs (an external API function for my physics lib): ...
    (comp.lang.c)
  • C# - getting binary data from .lib
    ... I'm trying to access a C++ .lib from C#. ... I can get an int back fine, ... WIN32DLL_API int create_wrapped(int id, int scale, unsigned char *image) ... public static extern int create_wrapped(int id, int scale, ...
    (microsoft.public.dotnet.framework.interop)