You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »

When compiling with a specific vendor's implementation of the C language, and related libraries, be aware that, unfortunately, standards conformance can differ from vendor to vendor.  Be certain to read your vendor's documentation to reduce the likelihood of accidentally relying on implementation-specific behavior or deviations.

Implementation-Specific Deviations

Implementation-specific deviations are listed below.  The Version column lists the latest version of the compiler or library that exhibits the behavior.

Microsoft Visual Studio

APIDescriptionVersion Link
<complex.h>Absent; __STDC_NO_COMPLEX__ is defined2012  
isblank()Absent2012  
<fenv.h>Absent2012  
<inttypes.h>Absent2012  

float_t, double_t, HUGE_VALF,
HUGE_VALL, INFINITY, NAN

Absent 2012  
#pragma FP_CONTRACTSpelled fp_contract instead of FP_CONTRACT2012 MSDN
fpclassify()Absent, use _fpclass() instead2012 MSDN
isfinite(), isinf()Absent, use _finite() or _finitef()instead2012 MSDN
isnan()Absent, use _isnan() or _isnanf() instead2012MSDN
isnormal()Absent, use _fpclass() instead 2012MSDN
signbit()Absent 2012  
acosh(), asinh(), atanh()Absent2012  
exp2(), expm1(), ilogb(), log1p(),
log2()
Absent2012  
scalbn()Absent; use _scalb() (or _scalbf() on x64 targets only) instead 2012 MSDN
cbrt()Absent 2012  
erf(), erfc(), lgamma(), tgamma()Absent2012 
nearbyint(), rint(), lrint(),
round(), lround(), trunk()
Absent 2012 
remainder(), remquo()Absent2012  
copysign()Absent; use _copysign() instead 2012 MSDN
nan(), nexttoward()Absent 2012  
nextafter()Absent; use _nextafter() or _nextafterf() instead 2012 MSDN
fdim()fmax(), fmin()Absent 2012  
fma()Absent 2012 
isgreater(), isgreaterequal(),
isless(), islessequal(),
isunordered()
Absent 2012  
<stdalign.h>Absent   
va_copy()Absent 2012  
<stdatomic.h>Absent 2012  
<stdbool.h>Absent; _Bool is not supported in /TC mode, but bool is supported in /TP mode2012 MSDN
max_align_tAbsent 2012  
Printing format specifier type fieldS is MSVC-specific; c, s, and z are not ANSI compatible; F is unsupported2012MSDN
Printing format specifier size fieldII32 and I64 are MSVC-specific; hw and l are not ANSI compatible; hh, jz and t unsupported2012MSDN
Scanning format specifier type fieldS is MSVC-specific; c and s are not ANSI compatible; p is unsupported2012 MSDN
Scanning format specifier size fieldI64 is MSVC-specific; h, l, and L prefixes are not ANSI compatible; hh, j, z, and t are unsupported2012 MSDN 
snprintf()Absent; use _snprintf() instead 2012MSDN 
vfscanf(), vscanf(), vsscanf()Absent 2012  
fopen(), freopen()Mode parameter not ANSI compatible; t, c, n, N, S, R, TD and css are MSVC extensions; x is
unsupported; see remarks
2012 MSDN
atoll()Absent; use _atoi64() instead 2012 MSDN 
strtof(), strtold()Absent 2012 
strtoll()Absent; use _strtoi64() instead 2012 MSDN 
strtoull()Absent; use _strtoui64() instead 2012 MSDN 
aligned_alloc()Absent; use _aligned_malloc() instead (beware, the parameter order is reversed)2012 MSDN 
at_quick_exit(), quick_exit()Absent 2012  
_Exit()Absent; use _exit() instead2012MSDN 
<stdnoreturn.h>Absent; use __declspec(noreturn) instead 2012 MSDN 
<tgmath.h>Absent 2012  
<threads.h>Absent2012  
TIME_UTC, struct timespec,
timespec_get()
Absent2012  
strftime(), wcsftime()z is not ANSI compatible; C, D, e, F, gG, h, n, r, R, tT, uV unsupported2012MSDN 
<uchar.h>Absent 2012  
vfwscanf(), vswscanf(), vwscanf()Absent2012  
fwide()Unsupported 2012 MSDN 
wcstof(), wcstold()Absent 2012  
wcstoll()Absent; use _wcstoi64() instead 2012 MSDN
wcstoull()Absent; use _wcstoui64() instead2012 MSDN 
iswblank()Absent 2012  
FLT_EVAL_METHOD, *_HAS_SUBNORM,
*_DECIMAL_DIG, *_TRUE_MIN
Absent 2012  

fopen() & freopen()

The C standard does not specify what happens with Windows newline characters (CRLF), and so care should be taken when working with text files.  For instance:

#include <stdio.h>
 
void func( void ) {
  FILE *fp = fopen("text_file.txt", "r");
  if (fp) {
    int counter = 0;
    while (!feof(fp) && !ferror(fp)) {
      ++counter;
      (void)fgetc(fp);
    }
    fclose(fp);
    printf("Number of characters read: %d\n", counter);
  }
}

 
// Contents of text_file.txt
This has
CRLF newlines
in it.

If you save the contents of text_file.txt with Windows line endings (CRLF) and run the program on Windows, it will print 30.  However, if you compile the application on a platform which does not use CRLF as its line endings, it will print 32.  This is because MSVC's text translation mode will translate the CRLF characters into a single LF character on input, and translate a single LF character to CRLF on output.  To ensure consistent behavior between platforms, consider opening the file in binary translation mode explicitly.

#include <stdio.h>
 
void func( void ) {
  FILE *fp = fopen("text_file.txt", "rb");
  if (fp) {
    int counter = 0;
    while (!feof(fp) && !ferror(fp)) {
      ++counter;
      (void)fgetc(fp);
    }
    fclose(fp);
    printf("Number of characters read: %d\n", counter);
  }
}

 This program will print 32 with the given text, regardless of platform.

 

  • No labels