You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "Chris Dyer (JIRA)" <ji...@apache.org> on 2009/12/18 21:44:18 UTC
[jira] Commented: (AVRO-47) Byte sequence to be represented as
void*
[ https://issues.apache.org/jira/browse/AVRO-47?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12792634#action_12792634 ]
Chris Dyer commented on AVRO-47:
--------------------------------
There is a lot of confusion about why void* is discouraged in c++. Its use is disfavored when it conceals type semantics that should be present.
But, there *are* cases when you want to conceal the type semantics associated with data: when you don't have a programmatic type associated with it! In those cases, programmars put it into a byte array or some other compressed format and refer to it with void*, since that reminds the reader of the code not to interpret it using an programmatic type. When c++ programmars see an array of uint_8's, they assume it has the semantics of "array of small, unsigned integers", which is explicitly not what we've got here- the member function isn't called putArrayOfSmallUnsignedIntegers. void* means - "i don't know what to make of this data- just copy it around as efficiently as possible and don't interpret it, ever". This is *exactly* what this interface should imply. I would strongly encourage you to drop uint_8* in favor of void*.
(As an aside, there are some other representational guarantees associated with types- the standard further specifies that void* will have char*-like semantics when it comes to alignment and representation).
> Byte sequence to be represented as void*
> ----------------------------------------
>
> Key: AVRO-47
> URL: https://issues.apache.org/jira/browse/AVRO-47
> Project: Avro
> Issue Type: Bug
> Components: c++
> Reporter: Arvind Jayaprakash
> Attachments: AVRO-47
>
>
> The current function prototype for serializin bytes is as follows:
> void putBytes(const uint8_t *val, size_t size)
> This is better written as
> void putBytes(const void *val, size_t size)
> Using void* in favour of an int based data type frees us from unnecessary casting opaque bytes from arbitrary stuctures/classes into "integer". This is consistent with say a function like memcpy()
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.