It is currently Thu May 23, 2013 9:03 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Allow 0 to be used with pseudotypes
PostPosted: Thu May 10, 2012 11:01 am 
Offline
Enthusiast
Enthusiast

Joined: Sat Dec 20, 2003 6:19 pm
Posts: 467
Location: Switzerland
Some external libraries take strings as arguments where
one is allowed to pass a 0 (null pointer) instead of an actual
string. Most of the time this means that some default value
will be used instead.

Currently there are two solutions, one is not using pseudotypes
which requires manual conversion and the other using an
uninitialized string variable like so:
Code:
s.s
Debug @s
function_call(s)


As pseudotypes are mostly used for interfacing with external
functions and since a null-pointer is actually a valid "empty
string" in PureBasic, I propose to allow passing a literal 0
for a pseudotype-argument. I do not think that this functionality
would also be useful for normal string type arguments. Hence
this request is only for pseudotypes.

Example:
Code:
ImportC "externalLib"
  bla(u.p-ascii)
EndImport

bla("")
u.s = ""
bla(u) ; <- the same

bla(0) ; <- not the same!
s.s
bla(s) ; <- the same as bla(0)



Additional consequences:
Currently there is some inconsistent behaviour. If I compile
in UNICODE mode, then any conversion to p-unicode will
be ignored (OK). But if I switch to compiling in ASCII mode,
it seems that even for the uninitialized string a conversion
to unicode is done and PB actually allocates a new string.

For my proposal to work, all pseudotype-conversions must
not touch a null-pointer (uninitialized string) and just pass it
on to the C function as a null-pointer.


Otherwise:
If the PB team is not inclined to implement this request,
please remove the inconsistency and always do a conversion
even if it is a ASCII-ASCII conversion so we never get to
pass a null-pointer by accident.


Cheers
Remi

_________________
Athlon64 3700+, 1024MB Ram, Radeon X1600


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye