Using GNU C Libraries and Other Data Structure Libraries on Mac / Windows / Linux.?

I want to know if the C library system / string / data structure / database, etc. is dependent. depend on the platform.

What are the things of these libraries that are platform specific.? for example like regex / string manipulation / sql hookups etc. are platform dependent.?

Can I use them on any platform for I / O / Paths files etc. the same way we do things in python using sys / os modules etc.?

I want to create a program that deals with strings, database (sqlite3, mysql, Oracle), data structures, file inputs and system paths. and can run on Windows, Linux and Mac when built on that platform. and I want it to be console-based.

Please do not recommend that I do this in other programming languages, I want the C people to answer please.

thank

+3


source to share


2 answers


Ok, if you are using the C standard library all is well. The GNU C library (glibc) is one of the implementations of the C standard and, for example, Microsoft has its own implementation.

From the user's point of view (yours), impementation doesn't matter. If you, for example,

#include <stdio.h>

      



then you can, on any standards-compliant platform, invoke fopen()

and then use fread()

for file I / O. Or any other standard C function.

Linux, Mac, and Windows are standards compliant (i.e. have implemented ISO C) and thus the standard features do the same on all platforms. The paths of the files you transfer to fopen()

are the same too. The fact that Windows uses a backslash (\) in the file path instead of the Unix path (forward slash //) does not matter: on Windows, in your C program, you are using Unix-style notation.

+2


source


For C library functions, I suggest you use functions at the POSIX level . This will (in theory at least) guarantee compatibility with other POSIX platforms.

If you are programming on linux using glibc

(i.e. in a regular C library) then the documentation is helpful enough to indicate what GNU extensions are, but the POSIX standard (link above) is the gold standard.

For other libraries, you will need to refer to the corresponding library.



Remember, if there are certain areas of incompatibility, you can use #ifdef

etc. around these bits and store specific machine elements in specific files.

The specific points that you mentioned: * the regexp functions PREIX ( regcomp

, regexec

, regerror

, regfree

) are part of the POSIX standard. * Most of the line management functions (for example strstr

) are part of the POSIX standard. Some (for example asprintf

) are GNU extensions. * SQL compatibility is not provided by the C library. You will need a specific C library to work with your SQL connection or to use something like libdbi

. You will need to look at the specific library to see what support exists on other platforms.

In particular, be careful with window manipulation (think of slashes versus backslashes and drive letters), in particular how they are entered by the user and what is passed to the function.

0


source







All Articles