Qbasicnews.com
October 22, 2019, 02:58:14 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1] 2
  Print  
Author Topic: Passing byte arrays instead of strings  (Read 8283 times)
AcetoliNe
New Member

Posts: 3


WWW
« on: January 26, 2005, 06:08:38 PM »

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?
Logged

o one escapes from life alive
relsoft
*/-\*
*****
Posts: 3927



WWW
« Reply #1 on: January 26, 2005, 11:40:22 PM »

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
Logged

y smiley is 24 bit.


Genso's Junkyard:
http://rel.betterwebber.com/
AcetoliNe
New Member

Posts: 3


WWW
« Reply #2 on: January 27, 2005, 02:08:21 AM »

Thanx!

My main problem was the '@' character. I though you had to use the '&' character like in C.
Logged

o one escapes from life alive
Jofers
Been there, done that
*****
Posts: 1040



WWW
« Reply #3 on: January 27, 2005, 06:01:05 AM »

'@' 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.
Logged
relsoft
*/-\*
*****
Posts: 3927



WWW
« Reply #4 on: January 29, 2005, 07:38:10 AM »

Quote from: "Jofers"
'@' 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. :*(
Logged

y smiley is 24 bit.


Genso's Junkyard:
http://rel.betterwebber.com/
Jofers
Been there, done that
*****
Posts: 1040



WWW
« Reply #5 on: January 29, 2005, 01:13:31 PM »

Why?  If you're editing old sources then they'll be 16-bit integers.

...and in that case, what would you use for "short"?
Logged
relsoft
*/-\*
*****
Posts: 3927



WWW
« Reply #6 on: January 30, 2005, 02:38:59 AM »

_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.
Logged

y smiley is 24 bit.


Genso's Junkyard:
http://rel.betterwebber.com/
Jofers
Been there, done that
*****
Posts: 1040



WWW
« Reply #7 on: January 30, 2005, 03:38:45 AM »

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?
Logged
v3cz0r
I hold this place together
*****
Posts: 924



WWW
« Reply #8 on: January 30, 2005, 03:46:38 AM »

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
Logged

na_th_an
*/-\*
*****
Posts: 8244



WWW
« Reply #9 on: January 30, 2005, 10:47:22 AM »

Quote from: "Jofers"
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.
Logged

SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Jofers
Been there, done that
*****
Posts: 1040



WWW
« Reply #10 on: January 30, 2005, 11:12:34 AM »

well... that's what I was thinking of with taht statement anyways.   American keyboards have no use for tilde whatsoever.

So... where is your semicolon then?  Did they just add a key?, and make the enter rectangular?

As for the suffix... it doesn't make any sense to have integer, double and single with a shortcut and not short and byte.  I think it's sufficient to at least add "@" for byte and make "%" short.  The "?" thing was just late night rambling Smiley
Logged
na_th_an
*/-\*
*****
Posts: 8244



WWW
« Reply #11 on: January 30, 2005, 11:20:26 AM »



I use sufixes, but since I began coding in VB I'm having the good practice of not use them and declare my variables. I think they should be only allowed for backwards compatibility and be considered "deprecated" from now on.
Logged

SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Jofers
Been there, done that
*****
Posts: 1040



WWW
« Reply #12 on: January 30, 2005, 11:26:05 AM »

wow... your keyboard's totally different.  That's kind of cool.

*shrug*  I like using them.  Really, if you wanted proper coding you'd force DIM declarations.  Suffixes just make life easier, that's their purpose.

How do you accent vowels?
Logged
na_th_an
*/-\*
*****
Posts: 8244



WWW
« Reply #13 on: January 30, 2005, 01:52:57 PM »

Look at the two keys that are marked red. You press them, then the vowel to get , , , . That's inherited from typewriters.

Yeah, suffixes make your life easier, and I do like them, but I find it more "stylish" and also quite useful to force yourself to declare variables. It may be a bummer at first, but you get used to it fast. That's what Option Explicit is designed to: if you add that clausule at the beginning of your code, all undeclared variables produce a compile-time error.
Logged

SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Jofers
Been there, done that
*****
Posts: 1040



WWW
« Reply #14 on: January 30, 2005, 02:36:06 PM »

Aha.  you clever bastards.

Yeah, I've dabbled plenty is strongly-typed languages (java, c, perl with strict).  I also agree with you on style and cleanliness.  But if you support suffixes, then support it right, that's all I'm saying.  Right now there's three types supported by suffixes, and there are two symbols for one type, it's inconsistent.

Actually, I really don't care.  But I have a tendency to get provoked by responses Smiley
Logged
Pages: [1] 2
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!