Four Js Development Tools Forum

Discussions by product => Genero BDL => Topic started by: Lu?s T. on March 15, 2016, 04:57:18 pm



Title: NULL in C
Post by: Lu?s T. on March 15, 2016, 04:57:18 pm
Hi,

I am porting a software from 2.51 to 3.0 and I am having errors in some C files, related to NULLs.

Do I have C functions to set a var to null and to test if a var is null?

Thanks in advance


Title: Re: NULL in C
Post by: Reuben B. on March 15, 2016, 10:56:10 pm
Hi,

You said 2.51 to 3.0, is it possible you meant 2.50 to 3.0 and are affected by this change in 2.51 https://4js.com/online_documentation/fjs-fgl-manual-html/#c_fgl_Migrate_to_251_cext_api.html 

If so, perhaps the advice there to explicitly link your c libraries to the ESQL/C might be what you need.

Reuben


Title: Re: NULL in C
Post by: Lu?s T. on March 16, 2016, 09:25:29 am
Hi Reuben,

Yes I meant 2.50 to 3.0. In any case I understood that, with 3.0, Genero is cutting its dependency with IBM.

It make sense to provide an alternative way to handle NULLs in C, as that is not dependent on the database, but on the 4GL language. If I want to define a C function that returns a NULL value in certain conditions, how do I do it?

I can allways do a function in 4GL (SetNull) and call it from C, but it should be a better way to do it, with some kind of MACRO or C library function.

Luis


Title: Re: NULL in C
Post by: Rene S. on March 16, 2016, 12:23:49 pm
Hi,
try this:

    pushquote("", 0);

an empty string is a NULL value.
Rene



Title: Re: NULL in C
Post by: Lu?s T. on March 16, 2016, 12:27:04 pm
I have the same problem to decimal. How should I do it?

And for other types like Integer, etc?


Title: Re: NULL in C
Post by: Rene S. on March 16, 2016, 12:30:08 pm
You can use this for any type.
Remember: LET var = "" is equivalent to INITIALIZE var TO NULL


Title: Re: NULL in C
Post by: Lu?s T. on March 16, 2016, 12:32:30 pm
Thanks. I'll try it.

And how do I test if a value is NULL in C?


Title: Re: NULL in C
Post by: Sebastien F. on March 16, 2016, 01:57:26 pm
Luis, what is your target database type?
Seb


Title: Re: NULL in C
Post by: Rene S. on March 16, 2016, 03:51:10 pm
#define MY_IS_INT_NULL(v) ((unsigned) v == 0x80000000)
#define MY_IS_SHORT_NULL(v) ((unsigned) v == 0x800)
#define MY_IS_DEC_NULL(v) (v.dec_pos < 0)
#define MY_IS_CHAR_NULL(v) (v[0] == '\0')
#define MY_IS_DOUBLE_NULL(v) (isnan(v))


Title: Re: NULL in C
Post by: Lu?s T. on March 16, 2016, 03:55:19 pm
Seb,

My target database is Informix.

Rene,

Thanks. In anycase I thing Genero should provide "official" macros for that.


Title: Re: NULL in C
Post by: Rene S. on March 16, 2016, 03:55:54 pm
#define MY_IS_INT_NULL(v) ((unsigned) v == 0x80000000)
#define MY_IS_SHORT_NULL(v) ((unsigned) v == 0x800)
#define MY_IS_DEC_NULL(v) (v.dec_pos < 0)
#define MY_IS_CHAR_NULL(v) (v[0] == '\0')
#define MY_IS_DOUBLE_NULL(v) (isnan(v))
#define MY_IS_SHORT_NULL(v) ((unsigned) v == 0x8000)