C is an old language. For instance, did you know that there would be no problem to use the . operator instead of the -> operator with pointers and that the -> was maintained for legacy reasons? see here.
Studying several C code, one can notice that most of the time structs are passed around using pointers instead of by value. Arrays are also passed by pointer.
Would be possible to change the syntax to pass structures by default as pointers? For instance, consider the following example:
struct Point {
float x;
float y;
};
struct Line {
Point! p0; // ! means that we want a value, not a pointer
Point! p1;
};
struct Line2 {
Point p0; // would be the same as Point*
Point p1;
}
void foobar(Line line) { // would mean Line* line
...
}
void foobaz(Line! line) { // would mean Line line
...
}
Let's not consider readability, for instance, some argue that -> makes explicit that is a pointer. That's not the point here.
Here is the question: what possible problems or corner cases could arise from using such syntax? For example: 'using such syntax, it would be impossible to do this or that'
Java actually works similar to this proposal: everything is a pointer under the hood. The difference is that Java has garbage collector and objects are always allocated in the heap (the object itself, not the 'pointer') while in C structs can be allocated in the stack (although most of the time I see allocated in the heap).
If one wonders why I am asking this, it is because I am creating a programming language for low level development and I want to optimize the syntax for the common case. Although I like the C language syntax itself, I've got frustated by having to use headers (update function signature in two places, for instance), lack of support for function overload (I don't like to write int_list_add, float_list_add) and similar.
Thank you all who already replied, but I am not trying to modify C. This is a research for my language that I don't have pretension to be used by others.
My language is for low-level development trying as much as possible to use high level stuff like OO stuff, high level functions, closures and so on. It won't be garbaged collector, using a memory model similar to C (similar, not equal).
The language will have pointers just as C: you can get the address of some variable, deference a pointer.
If it is so important to ask the question that I asked, here go the syntax of my language which, by the way, it is totally different from C, a proof that I am not trying to create a C clone.
record Point:
x : float
y : float
record Line:
p0 : Point!
p1 : Point!
record Line2:
p0 : Point
p1 : Point
function foobar : void
@line : Line
function foobaz : void
@line : Line!
As I've said, I want to optime the syntax of my language for the common case. So if I am going to pass by pointer almost all the time, I don't want to be using a * again, and again and again. The only problem (and this has nothing to do with my programming skills, but is philosofical issue) is that I can't see problems that could arise from not specifying explicitly that is a pointer.