Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Passing byte arrays instead of strings
#1
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
Reply
#2
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
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply
#3
Thanx!

My main problem was the '@' character. I though you had to use the '&' character like in C.
o one escapes from life alive
Reply
#4
'@' 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.
Reply
#5
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. :*(
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply
#6
Why? If you're editing old sources then they'll be 16-bit integers.

...and in that case, what would you use for "short"?
Reply
#7
_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.
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply
#8
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?
Reply
#9
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
Reply
#10
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.
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)