1 Oct 03:29
Re: main function signature?
Slawomir Lisznianski <slisznianski <at> c2-lang.org>
2004-10-01 01:29:19 GMT
2004-10-01 01:29:19 GMT
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: // file: System.h2 namespace System { typedef int RtCode; typedef int Argc; typedef []<[]<char const> any^> any^ Argv; typedef []<[]<char const> any^> any^ Env; // ... } We would then write: // file: UserMain.c2 #include <System.h2> using namespace System; RtCode Main(Argc, Argv) { } Using plain arrays is not a convenient method of dealing with sequences of characters. Arrays do not resize nor support encoding schemes (UTF, ASCII...) to name a few deficiencies. Instead, String class should be used by passing an array of const characters to its constructor: template <typename Ty, typename Enc, ...> class String { public: String([]<Ty const> any^ str); // ... }; // and somewhere else we might have: typedef String<char, AsciiEncoding<char>, ...> AsciiString; typedef String<char, UtfEncoding<char>, ...> Utf8String; typedef String<short, UtfEncoding<short>, ...> Utf16String; typedef String<int, UtfEncoding<int>, ...> Utf32String; // ... We could then write something like: using namespace System; RtCode Main(Argc argc, Argv argv) { AsciiString programName = argv[0]; // ... return skSuccessCode; } -- -- Slawomir Lisznianski C2 Language Group Principal (http://c2-lang.org) ------------------------------------------------------- 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 Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more http://productguide.itmanagersjournal.com/guidepromo.tmpl
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:
// file: System.h2
namespace System
{
typedef int RtCode;
typedef int Argc;
typedef []<[]<char const> any^> any^ Argv;
typedef []<[]<char const> any^> any^ Env;
// ...
}
We would then write:
// file: UserMain.c2
#include <System.h2>
using namespace System;
RtCode Main(Argc, Argv)
{
}
Using plain arrays is not a convenient method of dealing with sequences
of characters. Arrays do not resize nor support encoding schemes (UTF,
ASCII...) to name a few deficiencies. Instead, String class should be
used by passing an array of const characters to its constructor:
template <typename Ty, typename Enc, ...>
class String
{
public:
String([]<Ty const> any^ str);
// ...
};
// and somewhere else we might have:
typedef String<char, AsciiEncoding<char>, ...> AsciiString;
typedef String<char, UtfEncoding<char>, ...> Utf8String;
typedef String<short, UtfEncoding<short>, ...> Utf16String;
typedef String<int, UtfEncoding<int>, ...> Utf32String;
// ...
We could then write something like:
using namespace System;
RtCode Main(Argc argc, Argv argv)
{
AsciiString programName = argv[0];
// ...
return skSuccessCode;
}
RSS Feed