The correct order of inclusion for both <cstdio> and <stdio.h>?

I need to use system functions, for example. ftello()(defined in stdio.haccordance with the POSIX standard). I also need to use standard C ++ functions, for example. std::sprintf()(defined in cstdio, according to ISO C ++).

AFAIK, including only <cstdio>, does not guarantee the definition of non-standard C ++ material, therefore, I think I should include both. I read a long time ago that (for example) with gcc there may be problems with the order in which the file is added.

So, what is the correct inclusion order of both <cstdio>, and <stdio.h>? I am looking for a solution as much as possible for a cross platform (at least for gcc, suncc, intel C ++ / linux and mingw).

+3
source share
6 answers

OK, after some re-search, I finally came to the conclusion that to include the C ++ header first, and the C header is the right thing. For example, consider the following C ++ 0x header (from gcc):

/ Usr / include / c ++ / 4.3 / tr1_impl / cstdint:


// ...
#define __STDC_LIMIT_MACROS
#define __STDC_CONSTANT_MACROS
#include_next <stdint.h>
// ...

, , C99, C99 stdint.h. , C99 stdint.h , . ++ 0x stdint.h . , c99 stdint.h, cstdint, ++ 0x - stdint.h. , , . stdint.h - ( glibc ), C99 ++ 0x ( , ) gcc. ( , ++), ++ 0x , .

+2

.

SO.

+2

, , , .

, stdio.h C ( ) , <cstdio> - , ++ Standard Library, , , .

stdio.h cstdio , , .

+2

, , ftello() sprintf() stdio.h.

, , , , .

"", , .

0

. <cstdio> " " <stdio.h> (17.4.1.2 /4). ( ) std.

std::ftello(). using std::ftello;, .

0

, . , :

  • ,
  • , ,
  • , "" , boost SDL
  • ++
  • C

, . , , .

Another justification is that this ordering does not allow you to “hide” the dependencies on other headers, that is, these headers will not stand alone if they are included from other source files, since they always had built-in system libraries.

0
source

Source: https://habr.com/ru/post/1710941/


All Articles