Do the round brackets needed?

New to FreeBASIC? Post your questions here.
Post Reply
miilvyxg
Posts: 193
Joined: Dec 07, 2021 6:51

Do the round brackets needed?

Post by miilvyxg »

For example, with code like this:

Public Function Test() As ZString Ptr

Can the round brackets be omitted?

When calling it, which syntax is right?

result = Test vs result = Test()

I come from a language where the round brackets are absolutely required (C++).

Sometimes I saw FB code that simply omit them. So what is the correct syntax? Thanks.
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Do the round brackets needed?

Post by fxm »

When calling a function, parentheses surrounding the argument list (if any) are required only for function calls in expressions.
If there is no argument to pass, the parentheses become optional, but it is a common convention to place empty parentheses '()' after the function name, to signify a function call.

On the contrary, a Property in a Type should always be used without parentheses if it has no index parameter.
Post Reply