Specific libraries and C compiler defaults in Windows and Linux

1

I'd like to know why conio.h and strrev() of library string.h , there is no Linux.

Is there anything else that can only be done in Windows? And why this happens?

Is there anything that can only be done on Linux?

I did some research, but in most cases I found very superficial answers.

    
asked by anonymous 04.06.2018 / 15:57

2 answers

2

It does not exist in Windows either. This is not platform specific, it's C implementation, meaning the compiler has a default library that does not implement this API.

There is a specification of what the C language has, and the implementations must follow it to be called C. Then the compiler must have a standard library that conforms to the specification. It is true that, in general, it does not prohibit anything more, and conio is something more. But generally, compilers do not put extra stuff unless they are very useful, and very well implemented, which in practice will eventually force you into a new version of the specification. If you do not enter it is because you should not have it.

In fact the conio is too bad and should not be used. It was included in a compiler that wanted to have differential and followed by some others, but those who survived solidly did not do this.

A good Windows compiler such as VS-C ++, Clang, or MingW (GCC) does not have conio .

There are several libraries that only work on Windows, or only on Linux, or MacOS only, or only Android, etc. Even in different distributions of Linux or other Unix-like, or a variant of Windows, not to mention different versions.

But in general we are talking about platform APIs and not standard C's.

If you need more in-depth answers, ask more specific and detailed questions.

    
04.06.2018 / 16:54
0

The conio.h library and the strrev() function of the string.h library are not part of the C pattern. Avoid using them if your purpose is portabilidade .

An alternate implementation of strrev() can be something like:

#include <string.h>
#include <stdio.h>

char * strrev( char * s )
{
    char ch = 0;
    int j = 0;
    int i = strlen(s) - 1;

    while( i > j )
    {
        ch = s[i];
        s[i] = s[j];
        s[j] = ch;
        i--;
        j++;
    }

    return s;
}

int main( void )
{
    char str[] = "O rato roeu a roupa do rei de Roma!";
    printf( "%s\n", strrev( str ) );
    return 0;
}

Output:

!amoR ed ier od apuor a ueor otar O
    
11.06.2018 / 20:46