<ansi_h> (and Microsoft C [e.g. Visual Studio] Aarrrgggghhhhh...)
Posted: Thu Aug 27, 2020 2:30 am
I'm currently working on a new C program. First of all I'm porting the "ansi_h" header file from C68/PDQC, so that it will also be compatible with the QLC (normal Lattice C compiler for the QL) and EJC _AND_ (it's more easy to write a C program for Visual Studio C, and port it back to QDOS C) Microsoft C. The ansi_h file seems to be correct, but Microsoft C is horrible:
OK here my corrected <ansi_h> file (just a first try), which seems to be compatible with EJC (and hopefully with PDQC and C68) which seems to be compatible with Microsoft C from Visual Studio [2015], except for the problems with fopen and sscanf). The QLC (Lattice) compiler does unfortunately NOT support preprocessor statements like
#if (COMPILER == C68)
only
#if COMPILER
can be used (is true if COMPILER is not 0)
The improved Atari Compiler from PDQC does (but can currently not be used with EJC).
Can anyone test this improved ansi.h with C68 (I have not installed C68), if it's compatible?
Code: Select all
void myfunc() {
FILE *fp;
...
fp = fopen("myfile", "rb");
/* BOOM (with Microsoft C):
Schweregrad Code description project file line Unterdrückungszustand
Error C4996 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation,
use_CRT_SECURE_NO_WARNINGS. See online help for details. viewsroff d:\home\hps\projects\c\qdos\viewsroff\vsroff.c 206
*/
}
#if (COMPILER == C68)
only
#if COMPILER
can be used (is true if COMPILER is not 0)
The improved Atari Compiler from PDQC does (but can currently not be used with EJC).
Can anyone test this improved ansi.h with C68 (I have not installed C68), if it's compatible?
Code: Select all
#ifndef QDOS
#pragma once
#endif
/* The <ansi.h> header checks whether the compiler claims conformance to ANSI
* Standard C. If so, the symbol _ANSI is defined as 1, otherwise it is
* defined as 0. Based on the result, a macro
*
* _PROTOTYPE(function, params)
*
* is defined. This macro expands in different ways, generating either
* ANSI Standard C prototypes or old-style K&R (Kernighan & Ritchie)
* prototypes, as needed. Finally, some programs use _CONST, _VOIDSTAR etc
* in such a way that they are portable over both ANSI and K&R compilers.
* The appropriate macros are defined here.
*/
#ifndef _ANSI_H
#define _ANSI_H
/* ANSI C requires __STDC__ to be defined as 1 for an ANSI C compiler.
* Some half-ANSI compilers define it as 0. Get around this here.
*/
#define _ANSI 0 /* 0 if compiler is not ANSI C, 1 if it is */
/*
* Try and determine the compiler being used
*/
#ifdef _MSC_VER /* Microsoft C (e.g. C from VisualStudio) */
#define COMPILER MICROSOFTC
#define __STDC__ 1
#else
#ifdef TOS
#define COMPILER PDQC
#define LATTICE 1
#define __STDC__ 0
#else
#ifdef QDOS
# ifdef COMPILER
# if (COMPILER == C68)
# define C68 1
# else
/* if COMPILER != C68, you can extend other QDOS compilers here */
# define COMPILER UNKNOWN
# endif /* if COMPILER */
# else
# define COMPILER QLC
# define COMPILER_QLC 1
# define LATTICE 1
# define __STDC__ 0
# endif /* ifdef COMPILER */
#endif /* QDOS */
#endif /* TOS */
#endif /* _MSC_VER */
#ifndef _MSC_VER
#ifndef QDOS
#define QDOS 1
#endif
#ifndef COMPILER
#define COMPILER UNKNOWN
#endif /* QDOS */
#endif /* _MSC_VER */
#ifdef __STDC__ /* __STDC__ defined for (near) ANSI compilers*/
#if __STDC__ /* __STDC__ != 0 for conformant compilers */
#undef _ANSI /* get rid of above definition */
#define _ANSI 1 /* _ANSI = 1 for ANSI C compilers */
#endif
#endif
/* At this point, _ANSI has been set correctly to 0 or 1. Define the
* _PROTOTYPE macro to either expand both of its arguments (ANSI prototypes),
* only the function name (K&R prototypes).
*/
/* #if _ANSI || LATTICE */ /* Not supported by QL Lattice C */
#ifdef _ANSI
#if _ANSI
#define XYZ "XYZ_IS_DEFINED\n" /* I think this can be deleted, I have just used it for a test */
#define _PROTOTYPE(function, params) function params
#define _VOIDSTAR void *
#define _VOID void
#define _CONST const
#define _VOLATILE volatile
#define _SIZET size_t
#endif /* if _ANSI */
#else
#if LATTICE
#ifdef COMPILER_QLC
#define _PROTOTYPE(function, params) function params
#define _VOIDSTAR void *
#define _VOID void
#define _CONST
#define _VOLATILE
#define _SIZET int
#else
#define _PROTOTYPE(function, params) function params
#define _VOIDSTAR void *
#define _VOID void
#define _CONST const
#define _VOLATILE volatile
#define _SIZET size_t
#endif /* COMPILER_QLC */
#endif LATTICE
#endif /* _ANSI */
#else
#define _PROTOTYPE(function, params) function()
#define _VOIDSTAR void *
#define _VOID void
#define _CONST
#define _VOLATILE
#define _SIZET int
#endif /* _ANSI_H */