# How to write a block

**URL:** <https://www.ruby-forum.com/t/how-to-write-a-block/239566>\
**Category:** GNU Radio\
**Created:** [March 5, 2014, 2:32am UTC](https://www.ruby-forum.com/t/how-to-write-a-block/239566 "2014-03-05T02:32:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![musicdenotation](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea666f/32.png) [@musicdenotation](https://www.ruby-forum.com/u/musicdenotation)\
**Post date:** [March 5, 2014, 2:32am UTC](https://www.ruby-forum.com/t/how-to-write-a-block/239566/1 "2014-03-05T02:32:41Z")

</div>

hi,  
how to use the gr\_modtoolto write a block inherent from a  
in\_tree\_block,such as inherent from stream\_to \_vector  
BZS

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 5, 2014, 10:22am UTC](https://www.ruby-forum.com/t/how-to-write-a-block/239566/2 "2014-03-05T10:22:08Z")

</div>

-----BEGIN PGP SIGNED MESSAGE-----  
Hash: SHA1

Hi BZS,

just use gr\_modtool to generate a block of the same type  
(sync/hier/general/…) and then modify the include/blockname.h to  
inherit from the file you want.  
You will also have to use  
set(GR\_REQUIRED\_COMPONENTS RUNTIME BLOCKS)  
in the top-directory CMakeLists.txt (if the base class is in  
gnuradio::blocks, otherwise replace BLOCKS by that module).

Problem is, that inheriting from the in-tree classes won’t help you  
much in terms of functionality. Class structure of OOTs as well as  
in-tree modules is usually (let’s assume we’re talking about a block  
called bzt\_block):

bzt\_block: Specified only in include/bzt\_block.h. Most methods are  
purely virtual. Does not do anything, but specifies an interface to  
use, and an shared\_pointer factory (make) that returns a shared  
pointer to an instance of a subclass

bzt\_block\_impl: subclass of bzt\_block. Declared in  
lib/bzt\_block\_impl.h, defined in lib/bzt\_block\_imp.cc. Has all the  
methods. This class is usually hidden from “outside the module”, and  
is only accessed as an instance of the bzt\_block base class.

Greetings,  
Marcus

On 05.03.2014 02:25, 猪猪猪猪猪猪头 wrote:

> hi, how to use the gr\_modtoolto write a block inherent from a  
> in\_tree\_block,such as inherent from stream\_to \_vector BZS
> 
> \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ Discuss-gnuradio  
> mailing list [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [Discuss-gnuradio Info Page](https://lists.gnu.org/mailman/listinfo/discuss-gnuradio)

-----BEGIN PGP SIGNATURE-----  
Version: GnuPG v1  
Comment: Using GnuPG with Thunderbird - [http://www.enigmail.net/](http://www.enigmail.net/)

iQEcBAEBAgAGBQJTFuyDAAoJEBQ6EdjyzlHtOj4IALtvNH5kfPq7/4VNRdnyN36y  
IO64/bkIpkYD0G3LlWIKw56eh584/wXVTyNwvY+jwhdF3kk/vdWp309Y099OzUOk  
KCYJYKr7C6cK9XrjarHf1kgIu6cLJkyBgJ+k2Ni0IAFcB8ftlA2s8p4i4EjbD1d0  
DkXt2kOj3NZk3PHnO9bXShGlB25XKNJlrR4kwrDW8Lio3vRKlgA8r0ud94eZnz2w  
lcXRjzPrp5pSouQ6tz4E2iYmWye0vwR7fK2wbRYTDj3Cpzsa+j7MxsBHNGiOg3tB  
hPaWHIs97WtgV+LNgkhgboNqN85UOyzOI5dRpPU+cJKcCmzZtG557plkYRSIMK4=  
=mXdS  
-----END PGP SIGNATURE-----
