3 ms·
> and they have been transplanted as-is into Go Hum... I don't think anything can return an lvalue in C. Your first paragraph is not a huge concern when progr
by marcosdumay 6y ago
> and they have been transplanted as-is into Go
Hum... I don't think anything can return an lvalue in C.
Your first paragraph is not a huge concern when programming in C, declarations create lvalues, and that's it. I imagine you are thinking about C++, and yes, it's a constant source of problems there... So, Go made the concept much more complex than on the source.
- simiones 6y agoI think Go has exactly C's semantics here. The following is valid syntax with the same semantics in both: array[i] = 9 *pointer = 9 array[i].fieldName = 9 (*pointer).fieldName = 9 structValue.fieldName = 9 pointer->fieldName = 9 // Go equivalent: pointer.fieldName = 9 // you can also create a pointer to any of these lvalues // in either language with & Go has some additional syntax in map[key], but that behaves more strangely (it's an lvalue in that you can assign to it - map[key] = value - but you can't create a pointer to it - &(map[key]) is invalid syntax).
- simiones 6y ago> I don't think anything can return an lvalue in C. Btw, I was curious to check , here is an example of a function returning an lvalue: struct test { int a; } global; struct test* foo() { return &global; } int main (int argc, char**argv) { printf("%d", global.a); //wil print 0 foo()->a = 9; //or (*(foo())).a = 9; printf("%d", global.a); //will print 9 }