[erlang-questions] Passing binary strings to c port

Dave Challis <>
Mon Jun 6 17:10:09 CEST 2011


I've got an erlang program which uses binary strings (e.g. <<"abc">>), 
and a c port with some functions which operate on char arrays.

Is it safe to pass this binary string directly to c (using 
ei_decode_binary) for use in char arrays?

Or should I always use binary_to_list(<<"abc">>) before passing it to c, 
then decode using ei_decode_string?

My main worry is whether binary strings in erlang could contain the null 
character somewhere (e.g. passing <<"abc\0def">> to c port and decoding 
as a binary results in c seeing the string "abc").

Thanks,

-- 
Dave Challis




More information about the erlang-questions mailing list