Re: Malcolm's new book



[snips]

On Sun, 29 Jul 2007 22:36:39 +0100, Malcolm McLean wrote:

The problem is that I have to write the code with either ints or size_t's.
Being an int should fit all man, I chose int.

Bad choice.

int get_buff_len( buffer_t buff )

Quick: what happens if the length of the buffer is > INT_MAX? Hmm...
could be held in a size_t, which can handle the size of the largest
allowable object, but pukes on int.

Yeah, well. int.

This then leads to accusations of not having grasped the concept of
size_t.

Obviously, you haven't.

Of course it is pretty unlikely that someone would churn out 600
pages of C code but lack the intellectual capacity to understand that
size_t is the ANSI recommended way of representing amounts of memory.

Yet you get it wrong consistently.

I
even discuss the issue briefly in chapter 1.

Then you should know better.

But I have to explain my
reasons, whether you accept them or not, rather than be thought ignorant
of the existence of such a type.

If you know it, you should use it. Since there is *no* possible
justification for using int in such cases, as sizes are never negative and
can overflow the range of an int, you simply cannot use int reliably in
such cases - which is *exactly* why size_t exists in the first place.

Since you don't use size_t, one must conclude you're unaware of what it
is, what it's for and why it exists. If you *did* know, you'd have used
it, instead of int.
.



Relevant Pages

  • [PATCH] Numerous fixes to kernel-doc info in source files.
    ... static inline int ffs ... @buffer: where the data must be copied. ... * struct kfifo with kfree. ... @timer: ...
    (Linux-Kernel)
  • [UNIX] Multiple Vulnerabilities in Citadel/UX
    ... could allow complete control over a vulnerable server. ... Citadel server as can be seen by this simplistic code snippet: ... configuration buffers, leading to the possibility of carrying out a buffer ... int connect_to_host; ...
    (Securiteam)
  • Re: pushing the envelope with sockets
    ... receiving on the socket they are received (upto the buffer size), you can even change what happens if the buffer runs full. ... int read = S.EndReceive; ... class AsyncReader: Reader ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: [PATCH] Updated: Reworked Cell OProfile: SPU mutex lock fix
    ... arch-independent pieces of the OProfile kernel driver that this patch ... kernel driver patches. ... into the kernel buffer without holding the buffer_mutex lock. ... int spu_sync_start; ...
    (Linux-Kernel)
  • [PATCH] char: make functions static in synclinkmp.c
    ... int *eof, void *data) ... /* Allocate DMA buffers for the transmit and receive descriptor lists. ... * This buffer is used to pass an assembled frame to the line discipline. ...
    (Linux-Kernel)