On Mon, 2011-01-17 at 22:00 +1100, Ian Haywood wrote:
> On Mon, Jan 17, 2011 at 9:50 PM, Demosthenes Koptsis
> <demosthen...@gmail.com> wrote:
> >
> > Benoit sorry if you feel that i discuss C++ cases in a Gambas list but i
> > try to describe some cases of pointers and the usage of them in Gambas.
> IMHO the issue is C pointers aren't an easy topic and good conceptual
> understanding
> is important. Anyone who contemplates interfacing with a C API using
> pointers would need to sit down and read a standard C textbook to get a proper
> understanding: it's not something where you can give a few "quick tips" in a
> Gambas manual and then people can actually go away and use them.
> Similarly I can see how it's hard for Benoit and others to answer your 
> questions
> without launching into a ten-page tutorial on C pointers.

Yes and this will be the answers for any newbie who will start with
external functions.

i dont think that C++ programmers will come to Gambas to use external
functions, the opposite i think will be.

Gambas users will learn the basics of C++ and start use Gambas.

My case is that.

On the other hand i am not completely unaware of C++.
i just have not used to man(3) yet as it is expected.

> More importantly they have no other use in the language, so there's no point
> learning about gambas pointers unless you are prepared to learn C anyway.
> 
> My advice would be to make a choice:
> 1. sit down and learn basic C and how to use C pointers, then come
> back to this problem

i have already did this basic steps.
now i study other things as how c++ functions implements in Gambas.
The answer of Benoit was right about how to free a pointer,

cases which use Free() instruction of Gambas or
cases which call external functions to free a pointer which is declared
in Gambas.

This is a detail not easily shown and i must describe it for a Gambas
user, it is good to know it.


> 2. leave Gambas pointers alone and concentrate on other sections

> Ian
> 
> ------------------------------------------------------------------------------
> Protect Your Site and Customers from Malware Attacks
> Learn about various malware tactics and how to avoid them. Understand 
> malware threats, the impact they can have on your business, and how you 
> can protect your company and customers by using code signing.
> http://p.sf.net/sfu/oracle-sfdevnl
> _______________________________________________
> Gambas-user mailing list
> Gambas-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user


so, in previous example i think it works like this,

' Gambas module file
'char *get_current_dir_name(void);
Extern get_current_dir_name() As Pointer In "libc:6"
'void free(void *ptr);
Extern free_ptr(ptr As Pointer) In "libc:6" Exec "free"


Public Sub Main()

  Dim pFunc As Pointer
  Dim sWorkingDirectory As String

'get_current_dir_name
  pFunc = get_current_dir_name()
  Print pFunc
  
  sWorkingDirectory = Str@(pFunc)
  Print sWorkingDirectory

  free_ptr(pFunc)
  pFunc = 0

End

and i hope these examples and these cases will be helpful for anyone.


-- 
Regards,
Demosthenes Koptsis.


------------------------------------------------------------------------------
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand 
malware threats, the impact they can have on your business, and how you 
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user

Reply via email to