Subscribe for automatic updates: RSS icon RSS

Login icon Sign in for full access | Help icon Help
Advanced search

Pages: [1]
  Reply  |  Print  
Author Topic: NULL in C  (Read 14576 times)
Lu?s T.
Posts: 39


« 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
Reuben B.
Four Js
Posts: 1126


« Reply #1 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

Product Consultant (Asia Pacific)
Developer Relations Manager (Worldwide)
Author of https://4js.com/ask-reuben
Contributor to https://github.com/FourjsGenero
Lu?s T.
Posts: 39


« Reply #2 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
Rene S.
Four Js
Posts: 112


« Reply #3 on: March 16, 2016, 12:23:49 pm »

Hi,
try this:

    pushquote("", 0);

an empty string is a NULL value.
Rene

Lu?s T.
Posts: 39


« Reply #4 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?
Rene S.
Four Js
Posts: 112


« Reply #5 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
Lu?s T.
Posts: 39


« Reply #6 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?
Sebastien F.
Four Js
Posts: 545


« Reply #7 on: March 16, 2016, 01:57:26 pm »

Luis, what is your target database type?
Seb
Rene S.
Four Js
Posts: 112


« Reply #8 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))
Lu?s T.
Posts: 39


« Reply #9 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.
Rene S.
Four Js
Posts: 112


« Reply #10 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)
Pages: [1]
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.21 | SMF © 2015, Simple Machines