[Audacity-devel] WaveTrack.cpp - Nitpick
A free multi-track audio editor and recorder
Brought to you by:
aosiniao
From: <bf...@ew...> - 2002-05-08 21:03:53
|
I'm just looking at 'WaveTrack.cpp' to see whether I can reduce the number of warnings (currently 61). One of the first things that I note is int WaveTrack::sMaxDiskBlockSize = 1048576; /* 0x00100000 */ From its value this is clearly the maximum count of blocks on a disk to be used for some purpose (rather than the size of a block), and there is no indication that it is constant, so perhaps it isn't. More to the point, the C++ language, like C before it, only guarantees 16 bits for an int. There is a well defined size type for C, which is defined as "The type size_t is the unsigned integral type produced by the sizeof operator." In effect, size_t is the maximum size (count of items) of an array in C and a useful measure of the reach of a pointer. It is (and this is of direct relevance) the return type of fread and fwrite, being used precisely to size a disk by its count of blocks. I would guess that the designers of Audacity reasoned that it was likely to produse large files, and that it important not to break the underlying file system by trying to create files of more than a million or so blocks Some people are not happy using naked ints in production code in the first place (int should be reserved for those cases where its efficiency is important); and I would suggest that this value should be stored as size_t . This may be completely unacceptable if it must be a signed type. (Under ANSI C size_t is guaranteed to be unsigned), in which case I would suggest defining our own type for count of blocks, offsets et cetera: /* Type for holding count of blocks in a sound file */ typedef IndexBlock signed long int; thus it could be just as easily defined as something else, if it was thought to have been a mistake. On my system wxWindows actually does define the 32-bit integral types as ints, but then my compiler uses 32 bit ints. Any thoughts? Ben |