func before function

101 views
Skip to first unread message

valent...@gmail.com

unread,
Apr 27, 2020, 12:46:20 PM4/27/20
to golang-nuts
Why is it necessary to write func in go before declaring a function; if in C, when parsing a function, there is no such need?
Why "func sum(a, b int) int {...}" can't be "sum(a, b int) int {...}"

Ben Hoyt

unread,
Apr 27, 2020, 7:03:44 PM4/27/20
to golang-nuts
Why is it necessary to write func in go before declaring a function; if in C, when parsing a function, there is no such need?
Why "func sum(a, b int) int {...}" can't be "sum(a, b int) int {...}"

See discussion at very similar thread: https://groups.google.com/forum/#!topic/golang-nuts/fsNdDuR7D_c 

Volker Dobler

unread,
Apr 28, 2020, 6:22:21 AM4/28/20
to golang-nuts

On Monday, 27 April 2020 18:46:20 UTC+2, valen...@gmail.com wrote:
Why is it necessary to write func in go before declaring a function; if in C, when parsing a function, there is no such need?
Why "func sum(a, b int) int {...}" can't be "sum(a, b int) int {...}"

Of course it could be like that. But why should it be
like that? Is there any benefit? Did you think it through?
How about methods and function literals? Is the grammer
still non-ambiguous?

V.

Ali Hassan

unread,
Apr 28, 2020, 6:25:02 AM4/28/20
to golang-nuts
may be that's the way compiler understand where new function start 
Reply all
Reply to author
Forward
0 new messages