NULL in C

Started by Luís T., March 15, 2016, 04:57:18 PM

Previous topic - Next topic

Luís T.

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

Reuben B.

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
Product Consultant (Asia Pacific)
Developer Relations Manager (Worldwide)
Author of https://4js.com/ask-reuben
Contributor to https://github.com/FourjsGenero

Luís T.

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

Rene S.

Hi,
try this:

    pushquote("", 0);

an empty string is a NULL value.
Rene


Luís T.

I have the same problem to decimal. How should I do it?

And for other types like Integer, etc?

Rene S.

You can use this for any type.
Remember: LET var = "" is equivalent to INITIALIZE var TO NULL

Luís T.

Thanks. I'll try it.

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

Sebastien F.

Luis, what is your target database type?
Seb

Rene S.

#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))

Luís T.

Seb,

My target database is Informix.

Rene,

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

Rene S.

Quote from: 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))
#define MY_IS_SHORT_NULL(v) ((unsigned) v == 0x8000)