Type Question

New to FreeBASIC? Post your questions here.
nimdays
Posts: 180
Joined: May 29, 2014 22:01
Location: ID

Type Question

Postby nimdays » Dec 24, 2017 0:17

I don't know, but similar name doesn't throw warning or error.

Code: Select all

type a
    as integer b,c
end type

dim as a a
a.b = 10
a.c = 20

dim as a ptr ap = @a
?ap->b
?ap->c

ap->b = 30
ap->c = 40

?a.b
?a.c

sleep


Thanks.
sancho3
Posts: 231
Joined: Sep 30, 2017 3:22

Re: Type Question

Postby sancho3 » Dec 24, 2017 3:20

Do you think there should be a warning?
It seems to me that it is a feature of the compiler to be able to correctly distinguish between the two.
Everything works as expected in your sample code and there could be no way that you meant for the code to do anything else.
Also if I remember correctly C# allows this, and Python as well.
nimdays
Posts: 180
Joined: May 29, 2014 22:01
Location: ID

Re: Type Question

Postby nimdays » Dec 24, 2017 3:58

sancho3 wrote:Do you think there should be a warning?
It seems to me that it is a feature of the compiler to be able to correctly distinguish between the two.
Everything works as expected in your sample code and there could be no way that you meant for the code to do anything else.
Also if I remember correctly C# allows this, and Python as well.


Thanks, A bit curious about this one.
fxm
Posts: 7894
Joined: Apr 22, 2009 12:46
Location: Paris suburb, FRANCE

Re: Type Question

Postby fxm » Dec 24, 2017 7:50

This is allowed as long as the UDT does not have a member procedure or member field initializer, but I do not recommend declaring two different entities with the same name.
nimdays
Posts: 180
Joined: May 29, 2014 22:01
Location: ID

Re: Type Question

Postby nimdays » Dec 24, 2017 21:39

fxm wrote:This is allowed as long as the UDT does not have a member procedure or member field initializer, but I do not recommend declaring two different entities with the same name.


Thanks, I'll use different name next time.
Tourist Trap
Posts: 2293
Joined: Jun 02, 2015 16:24

Re: Type Question

Postby Tourist Trap » Jan 08, 2018 22:48

nimdays wrote:
Thanks, I'll use different name next time.

Hi,
from my side I'm using a convention that helps me knowing at one glance what is the familly of names I'm using.

Code: Select all

type A
   as integer _a
end type

dim a as A
a._a => 9

But you can follow fxm advices, they are valuable. Anyway, having a strong convention of naming helped me writing relatively long code without error.

For pointers I would append Ptr to the name:

Code: Select all

dim as A ptr    aPtr
SARG
Posts: 827
Joined: May 27, 2005 7:15
Location: FRANCE

Re: Type Question

Postby SARG » Jan 09, 2018 0:14

Hi,

A month ago I found that about naming guidelines. Could be usefull :
http://www.sourceformat.com/standard/as ... ADING1-779

There is also a page about comments :
http://www.sourceformat.com/standard/as ... ADING1-645
nimdays
Posts: 180
Joined: May 29, 2014 22:01
Location: ID

Re: Type Question

Postby nimdays » Jan 09, 2018 19:21

@Tourist Trap, Thanks for the advice.
@SARG, Thanks for the guideline.

For function name, Usually i use something like "Is_func" than "IsFunc"
Tourist Trap
Posts: 2293
Joined: Jun 02, 2015 16:24

Re: Type Question

Postby Tourist Trap » Jan 09, 2018 19:31

Hi nimdays, you are welcome. To continue on the steps of SARG's comment, I would propose you if you re interested this tutorial of mine, written some monthes ago when I tried to explore the question of naming in FB. fxm has answered there so there are some interesting advices, at least from him ;)
viewtopic.php?f=7&t=25182&hilit=alias%2A

Return to “Beginners”

Who is online

Users browsing this forum: No registered users and 2 guests