book icon indicating copy to clipboard operation
book copied to clipboard

Fix #3761 false about C

Open maxmosk opened this issue 1 year ago • 3 comments

There are not any methods in C

maxmosk avatar Nov 01 '23 09:11 maxmosk

While true, you can use the -> modifier in C to access members in a struct on a pointer. The arrow is just syntactic sugar. You could always write (*struct).member instead of struct->member

tolik518 avatar Nov 04 '23 12:11 tolik518

While true, you can use the -> modifier in C to access members in a struct on a pointer. The arrow is just syntactic sugar. You could always write (*struct).member instead of struct->member

Yes, but you can't call method in C anyway. Maybe better to rewrite all about ->?

maxmosk avatar Nov 04 '23 20:11 maxmosk

Yes, but you can't call method in C anyway. Maybe better to rewrite all about ->?

Yeah, I completely agree - talking about methods while mentioning C is wrong. I think C should be mentioned in the paragraph though and it should be rewritten imo.

tolik518 avatar Nov 04 '23 21:11 tolik518

While it is technically true that C does not have methods, you can absolutely store a function pointer on a struct in C and then call it using -> access. (There is a reason for C++’s use of that exact syntax. 😉) Closing this as the point here is not pedantic precision about C and C++ but rather getting the point across about how Rust differs from them. Thanks, though!

chriskrycho avatar Apr 03 '24 01:04 chriskrycho

@chriskrycho Calling functions methods is still wrong at that point though.

tolik518 avatar Apr 03 '24 06:04 tolik518