Re: pointers



Alexei A. Frounze wrote:
:) That's why I'd prefer declaring variables 3rd way, more like in Pascal,
where certain things are much more straightforward:

var
  a, b : array[0..10] of integer; (* both a and b are arrays of 10 ints *)
  p1, p2: ^integer; (* both p1 and p2 are pointers to int *)

I'd make it more cdecl-like:

  a, b: array 10 of int;
  p1, p2: pointer to int;

I once thought about making a C preprocessor to translate all declarations of this form into real C so they can be compiled.

main: function (argc: int,
                argv: pointer to pointer to char)
      returning int
{
  str: pointer to const char = "Hello World\n";
  puts(str);
  return 0;
}

I'm still not sure what syntax would be best for definitions with initialisations (possibly multiple initialisations).

a, b: int = 1;      // initialises both a and b to 1
a = 2, b = 3: int;  // initialises a to 2 and b to 3

Certainly the ability to declare objects of different types in a single declaration would be lost:

For example, the declaration:
  char c, *pc, **ppc, *(*pfrpc)();

Would become:
  c:     char;
  pc:    pointer to char;
  ppc:   pointer to char;
  pfrpc: pointer to function returning pointer to char;

Somewhat more typing, but much clearer!

--
Simon.
.



Relevant Pages

  • andersons equivalence method
    ... equivalences with ALGOL like or pascal like declarations and ... EQTO x: pointer to arrayfunction returning pointer ... array of pointer to function returning char ...
    (comp.lang.c)
  • Re: OT: C declaration syntax Re: generics and arrays and multi-class collections
    ... with the variable name, that is, a pointer is not char* p, but char ... but it kinda makes sense because that's also the way ... I hadn't even imagined that declarations could be so complex. ...
    (comp.lang.java.programmer)
  • address of functions return value
    ... assume the following declarations: ... If the call "func_1" is evaluated as a pointer to char, ... PGP Public Key: ...
    (comp.lang.c)
  • Re: Problem with va_ macros and arrays of arrays
    ... > the arrays passed to a ... > specific char, somewhat similar to what the standard function ... that with an array of struct, or possibly a pointer to a dynamic array ... > As I'm still a beginner in C without a copy of the standard I ...
    (comp.lang.c)
  • Re: Insufficient guarantees for null pointers?
    ... will the compiler know what the bounds are after converting that char * ... to an int *, if it could point to either of two arrays which happen to ... compares equal to the original pointer. ...
    (comp.std.c)