[PD-dev] [PD] more about float limitation

IOhannes m zmölnig zmoelnig at iem.at
Wed Feb 4 03:40:53 CET 2015

On 02/03/2015 08:29 PM, IOhannes m zmölnig wrote:
> On 02/03/2015 08:16 PM, IOhannes m zmölnig wrote:
>> EXTERN t_class *class_new32(...)
>> EXTERN t_class *class_new64(...)
> this btw, would also allow to write externals that provide both single-
> and double-prevision versions of an objectclass, without the need to
> change the extension.

they key to this is to provide dummy registration classes for the
unsupported precisions, so an external compiled for the "wrong"
architecture can be loaded by dlopen() but cannot actually *do* anything

> it's probably possible to all this in a single wrapper file, but i hope
> it's easier to understand without preprocessor magic.

a probably more readable example is the following:
suppose we have a implementation of a given external (whose author used
t_float/t_sample throughout, but has not done anything yet to port it to
a singe/double "phat" binary.
the objectclass is "mycobject" and lives in mycobject.c

then the following should be enough to make a phat binary:
    void mycobject_setup32();
    void mycobject_setup64();
    void mycobject_setup() {

and compile the original code with the above glue as follows:
$ cc -c -o mycobject-single.o mycobject.c -DPD_FLOATSIZE=32 \
$ cc -c -o mycobject-double.o mycobject.c -DPD_FLOATSIZE=64 \
$ cc -c -o mycobject-phat.o mycobject-phat.c
$ cc -o mycobject.pd_linux \
      mycobject-single.o mycobject-double.o mycobject-phat.o -lc

so the changes required to build such phat binaries are mainly (only¹)
in the build-system, and no (properly written) code needs be touched.


¹ the glue-code given above is trivial and it should be easy to write a
reuseable wrapper that is part of the build-system.
something like embedding the following file in the build-system
#define CONCAT_EXPAND(s1, s2) s1 ## s2
#define CONCAT(s1,s2) CONCAT_EXPAND(s1,s2)
void CONCAT(SETUP, 32);
void CONCAT(SETUP, 64);
void SETUP () {
 return 0;
and compiling it as (3rd line in the above example):
$ cc -c -o mycobject-phat.o phat.c -DSETUP=mycobject_setup

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://lists.puredata.info/pipermail/pd-dev/attachments/20150204/f631ad4b/attachment.sig>

More information about the Pd-dev mailing list