Re: Implicit int



In article <f_OdnThMeesf3jLb4p2dnAA@xxxxxx>,
Richard Heathfield <rjh@xxxxxxxxxxxxxxx> wrote:
Chacun a son gout, but I'm surprised that anyone finds them
oppressive, or even neutral. It's not as though they're hard to
compile or implement, or even would have been in the 1970s.
<shrug> Not my problem. :-) I am speaking from a user's perspective,
rather than an implementor's.

Well, so was I!

Let me take the three you quoted against
which I marked an E, and explain my reasoning:
Variable-length arrays: the problem here is with failure. The
introduction of VLAs does not magically increase the amount of memory
available to the program, obviously - so there inevitably comes a point
at which we can't allocate the amount we want. [...]

But this is nothing to do with VLAs. You will get the same
crunch with a fixed-length array if the length is too big and the
declaration is, eg, inside a deeply recursive procedure. Meanwhile
note that if you can't declare an array of size "n", then you must
declare one of size 1048576 [or whatever] that you have magically
decided is bigger than any possible "n", and you must then keep
testing your indices against "n" instead of against the actual size
of the array. This is (a) a waste of space; (b) a bug waiting to
happen when in fact "n > 1048576"; and (c) another bug lying in
wait when "i >= n" and you forgot to check -- and no bounds check
imposed by a safety-conscious compiler is going to discover this.
It's not as though all of these things have not happened time and
time again in actual C programs ....

long long int: an unnecessary wart. It does nothing that implementors
could not already do with long int, had they chosen so to do. [...]

Well, OK, but I quite like what the most recent version of
Algol has done, viz that "long long" has length determined by pragma,
but with a reasonably generous default:

Program:
LONG LONG REAL s2 = long long sqrt (2);
PROC fact = (INT i) LONG LONG INT: ( i > 1 | i * fact (i-1) | 1);
print ((s2, newline, fact (42)))
Output:
+1.4142135623730950488016887242096980785696718753769480732e +0
+1405006117752879898543142606244511569936384000000000

Not quite a "bignum", but if you want 1000-digit integers, you can get
them very easily, and all the standard operators and functions just work.

And if we *must* have a min-64-bit type, we should have called it "very
long int". :-)

OK! Or is it taking natural language programming too far?

mixed declarations and code: in my view, these make code harder to read.
I recognise that this is not a popular view, but if the declaration is
so far away from the code that it's hard to see, then the function (or
the block, at least) is probably too big anyway and should be
refactored.

It's not so much whether it's hard to see -- though that can
be a factor -- but whether declarations go in the "right place". It's
the initialiser rather than the identifier; I prefer

some long;
calculation;
int i = the result;

to

int i;
some long;
calculation;
i = the result;

as it not only saves a line but also saves you a possible bug from
using "i" before it is initialised. [Also better if "i" is constant,
of course.]

[There is still a way to go, of course, before C becomes Really
Useful .... I suppose you would classify operator declarations
somewhere around Z?]
One of the very few temptations C++ has to offer that I find hard to
resist is that of operator overloading, [...].

So there's hope yet?

--
Andy Walker, School of MathSci., Univ. of Nott'm, UK.
anw@xxxxxxxxxxxxxxxx
.



Relevant Pages

  • Re: Defining variable in C header file related doubt
    ... And it didn't compile, obviously. ... with int g declared in both files (and apparently ... "An external def1nition is an external declaration that is also a ... If an identif1er declared with external linkage is used in an ...
    (comp.lang.c)
  • Re: Finding a perfect number.
    ... That's really an algorithm question, ... several numbers you expect to use to populate the array in step 3. ... int number, i, split, total; ... declaration of arrays with a length which is dynamically determined. ...
    (comp.lang.c)
  • Re: More proof of errors going uncorrected among the "regs"
    ... of a declaration of an object with incomplete type. ... I've worked with code that had an array declared like that. ... unit containing `int array;' at file scope and with no ...
    (comp.lang.c)
  • Re: extern vars and linking
    ... > LOCAL int secondary_func{ ... > Compile and link libA.cpp as part of a library libA.a ... Including a declaration in any number of translation units is not going ... > C and CPP program any help or pointers would be much apprecaited. ...
    (comp.lang.cpp)
  • Re: Another C# marshaling question
    ... You will also have to change your function declaration to: ... public static extern int FF_Function( ... Then, what you have to do on return is marshal the array, like so: ... > public class FF_AO_OrderList ...
    (microsoft.public.dotnet.languages.csharp)