Re: main function signature?

Rajesh Walkay wrote:
> If pointers are second class citizens in C2, what would be the main 
> function signature? (-:

It depends on what type is str of in the following expression:

T str = "What am I";

Knowing the answer to the above will help us determine the signature of 
the main function.

In C++, T is of type:
const char*           <- pointer to const characters

In C2, T might be of type:
[]<char const> local^ <- reference to local array of
                          const characters

Since argv in C++ is a pointer to pointers to const chars, C2 argv would 
be declared as a reference to array of references to arrays of const 
characters. Our main function would then have a signature:

int Main(int, []<[]<char const> any^> any^);

I can just imagine your disappointment-- it surely looks easy to make a 
mistake.

The easiest way to make it shorter would be to declare a typedef in some 
standard header:

(Continue reading)

edA-qa | 1 Oct 18:07

Re: Clarified references, shortcut notation

Slawomir Lisznianski wrote:
>   T static^ t0;
>   T^ t1 = null;
>   T^ t2;
> Above, t0 and t1 are bound to null. t2 reference is of indeterminate 
> initial value.

C++ is confused when it comes to default construction and 
initialization.  I have the opinion that unless stated otherwise, all 
objects should be default initialized and all references should be null 
initialized.  Meaning t2 about starts as null.

This makes sense since it is the *normal* case in programming.  For 
those people that need to make fine-tine optimizations you could 
introduce this syntax:

	T^ t2 = uninit;

Even with performance in mind it is rare that one would specifically 
want to leave a value unitialized (an optimizer will remove the 
redundant initialization should it not be needed).

--

-- 
edA-qa mort-ora-y
Idea Architect
http://disemia.com/

-------------------------------------------------------
This SF.net email is sponsored by: IT Product Guide on ITManagersJournal
Use IT products in your business? Tell us what you think of them. Give us
(Continue reading)

Re: Clarified references, shortcut notation

edA-qa wrote:
> C++ is confused when it comes to default construction and 
> initialization.  I have the opinion that unless stated otherwise, all 
> objects should be default initialized and all references should be null 
> initialized.

I agree.

> Even with performance in mind it is rare that one would specifically 
> want to leave a value unitialized (an optimizer will remove the 
> redundant initialization should it not be needed).

Arrays are an exception and their initialization should be optional. 
Containers, such as Vector, will be implemented using a combination of 
uninitialized arrays and a placement new. Below is the proposed syntax 
for array initialization per Declarators document:

[]<int> a1[10](-1); // array of 10 integers initialized with -1

[]<int> a2[10];     // array of 10 uninitialized integers;
                     //   memory is aligned for constructing objects
                     //   of type int

[]<int> a3[10]();   // array of 10 zero-initialized integers

struct A {
   A();
   A(int);
};

(Continue reading)

edA-qa | 3 Oct 10:35

Revisit synonyms and references / typing

I would like to revist Slawek's example from before of the invoker series:

template<class T> void InvokerA( T^ fun )
{ fun.doSomething(); }

template<class T> void InvokerB( T^ fun )
{ InvokerA( fun ); }

...
T local;
T^ shared = new T();
InvokerB( local );
InvokerB( shared );

I believe this meets the requirements of no copying of the parameters 
without needing a reference.  Here's why, and it has to do with typing, 
an issue that has been somewhat ignored.

In my previous statemtn about references and instances, I am of the 
opinion, that in the way C2 works, the reference type has nothing to do 
with the actual instance type.  Therefore:

T local;
T^ sharedRef = new T();
T local^ localRef = @local;
T* ptr = /*something*/;

Unlike C/C++, in C2 all of the above references are used in the same 
fashion:
	local.func();
(Continue reading)

Re: Revisit synonyms and references / typing

edA-qa wrote:
> In my previous statemtn about references and instances, I am of the 
> opinion, that in the way C2 works, the reference type has nothing to do 
> with the actual instance type. 

For clarification, an instance is characterized by a duet of type and 
locality. Locality in turn determines types of references that are 
allowed to refer to that instance. The relationship between a reference 
type and locality of an instance is at the center of the C2 referencing 
model.

An object shall only be accessed via a reference (or less safely via a 
pointer). This is also true for value-types. Consider this example:

T localT;

Here, `localT' is a const reference to a stack object T (`localT' cannot 
be rebound). Object T will be destroyed deterministically, that is, when 
the `localT' reference goes out of scope.

T& st = localT;  // error, there cannot be a synonym to a (value) type,
                  //   only to a reference.

T local^& st = localT; // st: ok, synonym to reference to local T

One may think that the indexing operator brakes the "no synonym to 
value-type" rule:

[]<T> ar[5](); // array of 5 Ts initialized with default constructor

(Continue reading)


Gmane