Why do you use #ifndef IN #define IN in C language?

Asked 2 years ago, Updated 2 years ago, 28 views

<Header File>

#ifndef OUT
#define OUT
#endif

#ifndef IN
#define IN
#endif

<Source medium>

//*********************************************************************************************************************************
// o SHA256_Process() : A function that calls a compression function by dividing an input message with an arbitrary length into 512-bit blocks
// o Input : Pointer variable of Info - SHA-256 structure
//                        pszMessage - Pointer variables for input messages
//                        uDataLen - byte length of input message
// o Output: 
//*********************************************************************************************************************************
void SHA256_Process( OUT SHA256_INFO *Info, IN const BYTE *pszMessage, IN UINT uDataLen ) 
{
    if ((Info->uLowLength += (uDataLen << 3)) < 0)
        Info->uHighLength++;

    Info->uHighLength += (uDataLen >> 29);

    while (uDataLen >= SHA256_DIGEST_BLOCKLEN)
    {
        memcpy((UCHAR_PTR)Info->szBuffer, pszMessage, (SINT)SHA256_DIGEST_BLOCKLEN);
        SHA256_Transform((ULONG_PTR)Info->szBuffer, Info->uChainVar);
        pszMessage += SHA256_DIGEST_BLOCKLEN;
        uDataLen -= SHA256_DIGEST_BLOCKLEN;
    }

    memcpy((UCHAR_PTR)Info->szBuffer, pszMessage, uDataLen);
}

In the input part of the function, ...(OUT SHA256_INFO * INFO,...) I get input like this Putting the predefined structural variable *Info has been the case so far, but I don't know what OUT means.

c

2022-09-22 14:21

2 Answers

IN and OUT indicate whether the function's factors are used as inputs or outputs.

In c, you can have one default data type as the return value of the function, but when you actually code, you may need to get several results, not the default data type, after performing the function.

In this case, buffer pointers, etc. are sometimes handed over as a function factor to receive results. In this case, IN and OUT can be specified to clarify the nature of the function's factors.

In the example of the question, info and pszMessage are all function factors, but they give the data of pszMessage and get the result of manipulating the data in info. That's why OUT and IN were specified, respectively.


2022-09-22 14:21

When the compiler changes, it's probably like that so that there's no compilation error.

Compilers that do not support the keywords IN and OUT will have a compilation error without them.

In the case of MS compilers, there are often compiler extensions that you suggested. It depends on the case, but ifndef definition doesn't mean much and I think it's for meaning tagging.


2022-09-22 14:21

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.