Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - hungnguyengia

Pages: [1]
1
QB64 Discussion / Re: Is this statement right?
« on: July 21, 2021, 11:04:56 am »
Regarding NULL, what is the equivalent of C's NULL in QB64?

For example: how this C code translated to QB64?

IupOpen(NULL, NULL);

2
QB64 Discussion / Re: Is this statement right?
« on: July 21, 2021, 11:02:11 am »
On FreeBASIC, I could do something like this:

Type GENERIC_PTR As Any Ptr

Dim i as GENERIC_PTR

Could I do something similar with QB64? Because when everything is _OFFSET the code is almost impossible to understand. Intensive use of comments help a bit but this naming trick could really improve the situation.

For example:

int somefunc(struct somestruct *data);

On QB64 it will be:

function somefunc&(byval data as _offset)

Who know what type is data? The only way to read comments.

But something like this really helps:

Type SomeStructPtr As _OFFSET

This is way easier to understand:

function somefunc&(byval data as SomeStructPtr)

3
QB64 Discussion / Re: Is this statement right?
« on: July 21, 2021, 09:10:19 am »
How to translate this C function into QB64?

int       IupExecute(const char *filename, const char* parameters);

I think it's like this:

function IupExecute%(byval filename as _offset, byval parameters as _offset)

And call it like this:

fn$ = "file name"
pr$ = "pr1 pr2"

IupExecute(_offset(fn$), _offset(pr$))

On FreeBASIC, it's like this:

declare function IupExecute(byval filename as zstring ptr, byval parameters as zstring ptr) as integer

IupExecute("file name", "pr1 pr2")

There different is, we don't have to create two new variables just to be able to pass it to the function.

4
QB64 Discussion / Is this statement right?
« on: July 21, 2021, 07:12:46 am »
On QB64, we only have _OFFSET and _MEM.
Look at this example:

https://www.qb64.org/wiki/Windows_Libraries

As you see, they have to substitute any pointer types with the generic _OFFSET. This is real trouble when interfacing with C or even doing something useful with it own.

Look at this example:

int somefunc(struct somestruct *data);

Which translate to this in QB64:

function somefunc%(byval data as _OFFSET)

How we actually use this in code?

Instead of parse it directly like on FB, we have to create it first:

dim data as somestruct

data.somefield = somedata;
...

somefunc%(_OFFSET(data))

This is how we call it. Think about it. How inconvenient it is? It's also not type-safe as the generic pointer _OFFSET has no type and we have to workaround this by comment, intensive comments! Instead of a self explantory declaration on FB:

declare function somefunc(byval data as somestruct ptr) as integer

p/s: FB stands for FreeBASIC.

Pages: [1]