# Type Selectable GRC Blocks

**URL:** <https://www.ruby-forum.com/t/type-selectable-grc-blocks/242620>\
**Category:** GNU Radio\
**Created:** [July 8, 2015, 12:58am UTC](https://www.ruby-forum.com/t/type-selectable-grc-blocks/242620 "2015-07-08T00:58:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Detlef\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/58f4c7/32.png) [@Detlef\_R](https://www.ruby-forum.com/u/Detlef_R)\
**Post date:** [July 8, 2015, 12:58am UTC](https://www.ruby-forum.com/t/type-selectable-grc-blocks/242620/1 "2015-07-08T00:58:58Z")

</div>

Hi all,

I made a grc block that allows the user to select the input/output type  
using a drop down box. For a while, it seemed like what I had  
implemented  
worked fine. Recently, however, only selecting the complex data type  
works  
reliably, the other types sometimes cause the flowgraph to stop  
immediately  
with no error output. In some flowgraphs the block runs all types, in  
others it doesn’t.

I looked at the code and noticed that the first thing I do in  
general\_work  
is the following:

const _gr\_complex_ \*in = (const _gr\_complex_ \*) input\_items[0];  
_gr\_complex_ \*out = (_gr\_complex_ \*) output\_items[0];

This assumes the input/output types are gr\_complex, which makes me think  
is  
causing the problems I’m seeing. I tried to look in other built-in  
blocks  
to see how they work but it hasn’t cleared up my confusion. For example,  
in  
‘Stream to Tagged Stream’, which lets users select the type, the lines  
above are declared as follows:

const _unsigned char_ \*in = (const _unsigned char_ \*) input\_items[0];  
_unsigned char_ \*out = (_unsigned char_ \*) output\_items[0];

Why would this work if the user selects complex type from GRC?

The big question is, how do I properly define the buffer pointer types  
for  
user selectable type blocks in the C++ code?

v/r,  
Rich

---

<div class="post-metadata">

**Author:** ![reback](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b5ac83/32.png) [@reback](https://www.ruby-forum.com/u/reback)\
**Post date:** [July 8, 2015, 1:45am UTC](https://www.ruby-forum.com/t/type-selectable-grc-blocks/242620/2 "2015-07-08T01:45:42Z")

</div>

On 07.07.2015 15:57, Richard B. wrote:

> This assumes the input/output types are gr\_complex, which makes me think  
> is causing the problems I’m seeing. I tried to look in other built-in  
> blocks to see how they work but it hasn’t cleared up my confusion. For  
> example, in ‘Stream to Tagged Stream’, which lets users select the type,  
> the lines above are declared as follows:
> 
> const _unsigned char_ \*in = (const _unsigned char_ \*) input\_items[0];  
> _unsigned char_ \*out = (_unsigned char_ \*) output\_items[0];
> 
> Why would this work if the user selects complex type from GRC?

Because the block itself is agnostic of the data, and ‘unsigned char’ is  
a safe type to declare pointers. You’ll notice that we drag an ‘item  
size’ attribute around which is then used for the actual data copying.

> The big question is, how do I properly define the buffer pointer types  
> for user selectable type blocks in the C++ code?

There’s 2 cases: Either the block doesn’t care about the actual type  
(e.g. as in stream to tagged stream), then you use the char-pointer +  
item size. Or your block _does_ care about the type, then you need to  
reimplement the block for every type (e.g. the add blocks). We do have a  
template mechanism for this, mind you.

M
