How to Compare Symbols in C business Function.

KallaANaidu

Member
Dear All,

I want to develop a minor C Business Function for operation/production between 2 numbers, based on the parameter which gives 'type of operation/product' as input.

I developed a minor C business function which is used to do operation between 2 numbers.
Data structure has 4 parameters. 3 are input parameters other one is output parameter.

Requirement:

Parameter 1_ Input (any number can be passed)
Parameter 2_Input (any number can be passed)
Parameter 3_Input (type of operation)
Parameter 4_Output. (result)

If I pass 1 through parameter 3, addition cab be done.
If it is 2, subtraction can be done.
If it is 3, multiplication can be done.
If it is 4, division cab be done.

I have already done, passing numbers. Now I want to know how to pass the symbols like +, - , *, /.
So how to do comparison in C code.

Example:
If type of operation == + (I want to know this, how to compare. )
Result = Parameter 1+ Parameter 2


Thanks in advance.
 
Well, it depends on the data type of parm3.

if it's a JCHAR (1 character) then

if (parm3 == _J('+'))
{
/* add */
}
if (parm3 == _J('-'))
{
/* subtract */
}
etc.

if it's a "string" (array of characters) then

if (jdeStrcmp(parm3, _J("+"))==0)
{
/* add */
}
if (jdeStrcmp(parm3, _J("-"))==0)
{
/* subtract */
}
etc.

The _J stuff is a JDE macro to handle Unicode characters.

Craig
 
The _J stuff is a JDE macro to handle Unicode characters.

Craig

Hi-jacking this thread.

I've been thinking, can't we dispense with all the
Code:
_J("My String Literal")
stuff and simply go with:
Code:
L"My String Literal"

At this point we are not ever going to recompile the entire code base as single byte characters. In fact was there ever a time when we needed to be able to switch back and forth?
 
Craig,

first of all thanks a lot for your response.

i wrote the same logic as mentioned above. but BSFN not getting executed. here i am copying .c and .h files of BSFN. please have look and can you let me know, where i am doing wrong in the code.

SourceFile_H (.h)



#ifndef __B5700002_H
#define __B5700002_H


#ifndef DATASTRUCTURE_D5700001
#define DATASTRUCTURE_D5700001


typedef struct tagDSD5700001
{
MATH_NUMERIC mnInputOne;
MATH_NUMERIC mnInputTwo;
MATH_NUMERIC mnOutPut;
JCHAR cTypeOfOperation;
} DSD5700001, *LPDSD5700001;

#define IDERRmnInputOne_1 1L
#define IDERRmnInputTwo_2 2L
#define IDERRmnOutPut_4 4L
#define IDERRcTypeOfOperation_6 6L


#endif






/*****************************************************************************
* Source Preprocessor Definitions
****************************************************************************/
#if defined (JDEBFRTN)
#undef JDEBFRTN
#endif

#if defined (WIN32)
#if defined (WIN32)
#define JDEBFRTN(r) __declspec(dllexport) r
#else
#define JDEBFRTN(r) __declspec(dllimport) r
#endif
#else
#define JDEBFRTN(r) r
#endif

/*****************************************************************************
* Business Function Prototypes
****************************************************************************/
JDEBFRTN (ID) JDEBFWINAPI ProductBetween2Numbers (LPBHVRCOM lpBhvrCom, LPVOID lpVoid, LPDSD5700001 lpDS);


/*****************************************************************************
* Internal Function Prototypes
****************************************************************************/

#endif /* __B5700002_H */

SouceFile_C (.c)

JDEBFRTN (ID) JDEBFWINAPI ProductBetween2Numbers (LPBHVRCOM lpBhvrCom, LPVOID lpVoid, LPDSD5700001 lpDS)

{
/************************************************************************
* Variable declarations
************************************************************************/

JCHAR cTypeOfOperation = _J('+');
/************************************************************************
* Declare structures
************************************************************************/

/************************************************************************
* Declare pointers
************************************************************************/
/************************************************************************
* Check for NULL pointers
************************************************************************/
if ((lpBhvrCom == (LPBHVRCOM) NULL) ||
(lpVoid == (LPVOID) NULL) ||
(lpDS == (LPDSD5700001) NULL))
{
jdeErrorSet (lpBhvrCom, lpVoid, (ID) 0, _J("4363"), (LPVOID) NULL);
return ER_ERROR;
}

/************************************************************************
* Set pointers
************************************************************************/

/************************************************************************
* Main Processing
************************************************************************/
if (cTypeOfOperation == _J('+'))
{
MathAdd(&lpDS->mnOutPut, &lpDS->mnInputOne, &lpDS->mnInputTwo);
}
else if (cTypeOfOperation == _J('-'))
{
MathSubtract(&lpDS->mnOutPut, &lpDS->mnInputOne, &lpDS->mnInputTwo);
}


/************************************************************************
* Function Clean Up
************************************************************************/

return (ER_SUCCESS);
}



Thanks Craig in advance.

Naidu.
 
Hi-jacking this thread.

I've been thinking, can't we dispense with all the
Code:
_J("My String Literal")
stuff and simply go with:
Code:
L"My String Literal"

At this point we are not ever going to recompile the entire code base as single byte characters. In fact was there ever a time when we needed to be able to switch back and forth?

Brian,
The answer is no... while it is true that could work on Windows (wchar is UTF-16LE ... 16 bit little-endian), using the L prefix and wchar type for C-based strings on most UNIXes gives you 32 bit wide characters, except on AIX where you get 16 bits (I will note tho, that wchars on AIX are also 32 bits if you use their compiler in 64bit mode....) . On the other three UNIX platforms, Oracle/JDE ships an executable call "scan" or "scan_linux" which is basically a custom UNIX preprocessor for converting the _J based code into UTF-16 with byte ordering (big or little endian-ness) that matches the underlying platform's architecture (Linux and Windows, little endian, the rest, big endian.)

So, if you switch to "L", you are forever tying yourself to windows or IBMi or AIX 32 bit.
 
Last edited:
Thanks John for the detailed explanation. Guess I will keep using the _J macro to ensure code is cross platform compatible. I always assumed L"MyString" was part of Standard (ANSI) C and not a vendor/compiler specific construct. Documentation for GCC seems to indicate that the proper way to denote wide character is also L"MyString".

Edit 1:
Re-read your explanation. So what you are saying is that L"MyString" IS standard C, however, the implementation changes depending on platform. Windows it might be a two byte character but on Linux it might be a 4 byte character.

But JDE wants strings to be two byte chars regardless of the platform????
 
Last edited:
When you say it's not getting executed, do you mean it's not executing as you expect it to? or that the function is not being called?

Based on the code I think it will always perform addition because you are testing against the variable cTypeOfOperation (assigned the value '+') rather than the parameter lpDS->cTypeOfOperation.

Craig
 
When you say it's not getting executed, do you mean it's not executing as you expect it to? or that the function is not being called?

...and if it is not being called, make sure that you build it and it builds w/o any errors. I still forget to do that sometimes.
 
So what you are saying is that L"MyString" IS standard C, however, the implementation changes depending on platform. Windows it might be a two byte character but on Linux it might be a 4 byte character.

But JDE wants strings to be two byte chars regardless of the platform????

Yep, right on both counts.

The IBM ICU (International Components for Unicode) library, used by JDE, also wants it's basic char type, which is "XMLCh", to be 2 bytes. I'm pretty sure this has a lot to do with it.
 
Back
Top