Search found 11985 matches

by fxm
Jul 25, 2013 16:55
Forum: Beginners
Topic: new to freebasic
Replies: 3
Views: 428

Re: new to freebasic

Hi sokken, welcome to forum!

I think the first thing is to well study the documentation DO...LOOP and test the different proposed examples.
by fxm
Jul 24, 2013 19:52
Forum: Beginners
Topic: [S] Define problem: Variable not declared
Replies: 3
Views: 1282

Re: [S] Define problem: Variable not declared

Keyword #DEFINE in documentation:
.....
Note: In the function-like macro declaration, the identifier should be followed by the opening parentheses (() immediately without any white-space in between, otherwise the compiler will treat it as part of the body.
.....
by fxm
Jul 24, 2013 16:27
Forum: General
Topic: [S] WStrings, pointers and memcpy
Replies: 20
Views: 2655

Re: [..] WStrings, pointers and memcpy

Another example: If you want know the current size of the memory allocated to the character data of a var-len string, you must access the third integer value of the string descriptor: Dim As String s = "Hello FreeBASIC!" '' This next line is more clear than the last three Print Cast(Intege...
by fxm
Jul 24, 2013 14:19
Forum: General
Topic: [S] WStrings, pointers and memcpy
Replies: 20
Views: 2655

Re: [..] WStrings, pointers and memcpy

To avoid a compiler warning on a pointer hacking, one workaround without to code a pointer casting can be to use a temporary intermediary "Any Type" pointer which is obviously compatible any pointer! Example: '' First code block with a compiler warning Dim As Wstring Ptr pw1 Dim As Ubyte P...
by fxm
Jul 24, 2013 9:03
Forum: General
Topic: [S] WStrings, pointers and memcpy
Replies: 20
Views: 2655

Re: [..] WStrings, pointers and memcpy

There are exceptions, maybe if you're casting to HWND, or doing something particularly hackish, but sometimes people assume the warning is just an annoyance, cast it away, and leave a bug lurking. To be funny, I would say that the example of the documentation for the keyword CPTR should be an examp...
by fxm
Jul 24, 2013 5:34
Forum: General
Topic: [S] WStrings, pointers and memcpy
Replies: 20
Views: 2655

Re: [..] WStrings, pointers and memcpy

I think well-written code should have no warnings. But casting away a warning isn't always the best approach, and may end up masking a bug. Consider as example the program of matwachich above, and the two functions "WStr_t.get_ptr()" and "WStr_t.get_ptr(as uinteger)", which retu...
by fxm
Jul 23, 2013 19:32
Forum: General
Topic: [S] WStrings, pointers and memcpy
Replies: 20
Views: 2655

Re: [..] WStrings, pointers and memcpy

Does this mean that you prefer to leave the compiler warnings ("Suspicious pointer assignment"), either eyes closed in trusting in its conversion, or in checking its conversion? In addition, these compiler warnings are annoying for debugging program syntax! I prefer to explicitly specify m...
by fxm
Jul 23, 2013 18:04
Forum: Beginners
Topic: NULL equivalent in freeBASIC
Replies: 11
Views: 5066

Re: NULL equivalent in freeBASIC

NULL is a macro in C defined in the header <stddef.h>, and C++ inherits it (and of course places it in the header <cstddef>, as per the usual mapping between C header names and C++ header names). Note that at one time C seems to have placed NULL in <stdio.h> The definition of NULL for C and C++ dif...
by fxm
Jul 23, 2013 16:54
Forum: Beginners
Topic: NULL equivalent in freeBASIC
Replies: 11
Views: 5066

Re: NULL equivalent in freeBASIC

I thought that the code:
int x = NULL;
is legal C++.
Because of this and the ensuing confusion, C++11 now has a keyword 'nullptr' representing a null pointer:
int* ptr = nullptr;
by fxm
Jul 23, 2013 16:14
Forum: Beginners
Topic: NULL equivalent in freeBASIC
Replies: 11
Views: 5066

Re: NULL equivalent in freeBASIC

D.J.Peters wrote:

Code: Select all

#ifndef NULL
  #define NULL cptr(any ptr, 0)
#endif
Yes, but if you want to use 'NULL' with other variables than any pointer, a compiler warning occurs: 'Implicit conversion'.
My definition is less "pure C" but more convenient (no warning with any type of variable)!
by fxm
Jul 23, 2013 15:21
Forum: Beginners
Topic: NULL equivalent in freeBASIC
Replies: 11
Views: 5066

Re: NULL equivalent in freeBASIC

Code: Select all

#Ifndef NULL
  #Define NULL 0
#Endif
by fxm
Jul 23, 2013 15:04
Forum: Community Discussion
Topic: Abstract/Virtual destructor/method behaviour
Replies: 229
Views: 50524

Re: Abstract/Virtual destructor/method behaviour

dkl, Referring to my post just above (http://www.freebasic.net/forum/viewtopic.php?p=188876#p188876): - In a future release, can we expect to a right solution for that problem of cascading virtual operators as "Let" and "Cast", because they cannot be called with a syntax like &qu...
by fxm
Jul 23, 2013 5:45
Forum: General
Topic: [S] WStrings, pointers and memcpy
Replies: 20
Views: 2655

Re: [..] WStrings, pointers and memcpy

Very small remark about your casting on function results: - When the variable of the return instruction is compatible to the return declaration of the function, there is no need to cast this variable before return, because anyway the compiler already does it without even warning message. - The same...
by fxm
Jul 22, 2013 21:00
Forum: General
Topic: [S] WStrings, pointers and memcpy
Replies: 20
Views: 2655

Re: [..] WStrings, pointers and memcpy

How to keep private the three member data: At first, by defining two member operators "+=" (that can access private data), you can then extremely simplify the two non-member operators "+" by reducing their body to two high level instructions. #include "crt.bi" #define ...
by fxm
Jul 22, 2013 19:33
Forum: General
Topic: [S] WStrings, pointers and memcpy
Replies: 20
Views: 2655

Re: [..] WStrings, pointers and memcpy

Ok in order to optimize the execution speed.
The three member data ("__data", "__str_len" and "__allocated") are like those of a descriptor for var-len string.