W dniu wtorek, 20 listopada 2012 11:54:10 UTC+1 użytkownik Bart napisał:
the question is how syntax to choose to distinguish between
pointers-to-one and pointers-to-many in such cases:
void print(char* text) //pointer to undefined many
{
}
void print(char(1)* text) //pointer to one ?
{
}
also think sometimes (like here) if java-like
syntax wouldnt be clearer
char a; //a is adress to one
char[] a; //a is adress to undefined many
char[16] a; //a is adress to chunk of 16 chars
it seem clearer and *a could be reserved
eventually for old way
In my opinion, C type syntax is broken. And that's not just the convoluted
syntax.
It's because char[] means different things in different contexts: an array
in some places, and a pointer in another:
char a[]={65,66,67}; // array
void fn (char[] a); // pointer
char[] meaning array would be illegal in a parameter context, but insteadof
leaving that hole in the 'map' of possible types, everything moves up one
instead! The penchant for C to gloss over any dereferences needed - or not
needed - to index an array/pointer, just confuses things further.
I think you have your work cut out...
I do not understand 'cut out' phrase, but
I am thinking over applying logical
improvements for about and almost 10 years
till now and some good and logical ideas
(ways of improvements) arose
here this proposal seem also logical and
good one finally here (though some think
up over it is always good thing):
this could be considered as adding some
support for arrays in c, it would be this
way (as I repeat):
some length of operator should work
on arrays - in many cases it should work
in static (compiler) time, on some cases
then should use dynamic length info provided
in function call
arrays passing should offer some new way
of it
void foo(int some)
{
ShowBox( lengthof (some) );
//should give one - this is from compilet time static type analisis (givesone for all no arrays)
}
void foo(int[16] some)
{
ShowBox( lengthof (some) );
// should give 16 - compiler time info
}
void foo(int[] table)
{
ShowBox( lengthof (some) );
// this should give result based on number passed on stack (which then goes probably from static compiler info knowledge)
}
old pointer ways,
void foo(int* some)
void foo(int (*some)[16])
should probably be working to in old way,
thought probably pointer-to-one pointer-to-many type guarding should be used here too
(to skip off by casting if need probably)
this is logical and would work, some
syntaxic question as to use "int[] a" or
"int a[]" or lengthof(a) or lenghtof(a[]) or sizeof(a[]) would be for otherdetailed consideration maybe, but this would support
arrays reasonably nicely