Posts: 3
Threads: 2
Joined: Jan 2005
I have a question concerning pointers in fb:
consider calling a windows function that takes a string as a parameter under fb. It would look something like this:
Code:
Dim MyString as String
MyString = "Hello"
returncode = DoSomething (MyString)
Now, say that instead of a string, we used an array of bytes. How should we pass this to the function?
In C, it would look like this:
Code:
returncode = DoSomethiing ((const char *)&MyString[0])
How should this be written in fb?
o one escapes from life alive
Posts: 3,288
Threads: 167
Joined: Nov 2001
Code:
dim a(1000) as Ubyte
dim apooh as ubyte ptr
apooh = @a(0)
b = funky(apooh)
or
b = funky(@a(0))
function funky(byval a as ubyte ptr)
end function
Posts: 3
Threads: 2
Joined: Jan 2005
Thanx!
My main problem was the '@' character. I though you had to use the '&' character like in C.
o one escapes from life alive
Posts: 979
Threads: 27
Joined: Aug 2001
'@' is so much more logical, methinks. "at", the "pointer at"
However, we need some new types suffixes. There is much wasting in that areas.
For instance, "%" and "&" both refer to integers, while bytes have nothing. Of course, "@" and "*" could confuse the parser, and with "^", "+" & "-" taken out, that leaves only "~" free in that area.
Here's my proposed list:
~ - byte
% - short
& - integer/long
! - single
# - double
$ - string
The "%" switcharound wouldn't hurt backwards compatibility with QB because integers were 16-bit anyways, and you now have pretty much all the types covered.
Posts: 3,288
Threads: 167
Joined: Nov 2001
Quote:'@' is so much more logical, methinks. "at", the "pointer at"
However, we need some new types suffixes. There is much wasting in that areas.
For instance, "%" and "&" both refer to integers, while bytes have nothing. Of course, "@" and "*" could confuse the parser, and with "^", "+" & "-" taken out, that leaves only "~" free in that area.
Here's my proposed list:
~ - byte
% - short
& - integer/long
! - single
# - double
$ - string
The "%" switcharound wouldn't hurt backwards compatibility with QB because integers were 16-bit anyways, and you now have pretty much all the types covered.
This would be a cool addition. But I think % should still be integer cause there will be lotsof headaches on my part editing my old sources. :*(
Posts: 979
Threads: 27
Joined: Aug 2001
Why? If you're editing old sources then they'll be 16-bit integers.
...and in that case, what would you use for "short"?
Posts: 3,288
Threads: 167
Joined: Nov 2001
_S?
Like 1000_S * 1_S. It's a new datatype so why not make a new suffix.
There's also a prob with "~" since the tilde is not supported on some keyboards. I believe Spanish keyboards don't have the tilde.
Posts: 979
Threads: 27
Joined: Aug 2001
Why would spanish keyboards not support tilde? Their alphabet has tildes all over the place!
I imagine that since the underscore is alphanumeric, it would think it part of a variable name. So I guess tilde is out. Let's recap on our punctuation:
~ - not support on some keyboards.
! - presently single
@ - pointer symbol
# - presently double
$ - presently string
% - presently integer, proposed as short
^ - exponent operator
& - presently long, proposed as integer
* - multiplication operator
() - parenthesis (duh)
- - subtraction operator
_ - underscore (alphanumeric)
+ - addition operator
= - reserved for equating.
| - pipe is unused
\ - escape character in strings, integer division operator.
{} - unused, that I know of?
[] - unused, that I know of?
: - line concatenator
; - semicolon unused (taht I know of)
' - comment symbol
" - string quotes
< - less than operator
, - comma used in function calling
> - greater than operator
. - period used as decimal
? - question mark is unused
/ - division operator.
That leaves us with:
@, assuming no conflicts with parsing pointers
|, it's a pipe. not sure what you could do with that, pipes suck
;, semicolon, still not a good idea.
?, our best shot, but would it make things confusing?
There are obviously a lot of problems with this. A byte would be nice. If there are no parsing problems, I'd continue with the suggestion to assign "%" with short integers, and "@" to byte.
? could be some kind of indicator for unsigned.
myvar?@
It's cryptic, but so is myvar#...
Any other ideas?
Posts: 922
Threads: 15
Joined: Jun 2003
Yeah, the idea is: no new suffixes at all :P
It will end up like powerbasic, "thisisadword???" (declaring it once would be faster than pressing shift+? 3 times each time you use the identifier.. a bunch of "?"'s make the source code look like a joke, a bad one).
[] are used for pointer indexing, {} will be used with the var initializers and ; is used in many quirk QB statements like PRINT
Posts: 6,419
Threads: 74
Joined: Mar 2002
Quote:Why would spanish keyboards not support tilde? Their alphabet has tildes all over the place!
False. We only have a tilde in "ñ". And that is considered a different letter, not just a "n"+"~", so we have it in a separate key, to the right of "L".
Until some time ago, we had to hit ALT+126 to get the tilde. Now it can be gotten with ALT GR + 4, but most people don't know that 'cause it is not shown on the keyboard.