__file__

I am upgrading a significant number of MS C subprograms from VS 2008 to 2017. They must be compiled into a DLL for use by simulation models. /FC has been inserted in preprocessor definitions of project properties.

Can somebody please suggest how to correct the situation shown below. The void writedocstat statements in hsglob.h and hsglob.c are unchanged from VS 2008. So is the writedocstat line in chshft.c.

Hsglob.h
void writedocstat(char* writer, short docstat[STA][DOC], REAL runno, short dcall);

Hsglob.c
void writedocstat(char* writer, short docstat[STA][DOC], REAL runno, short dcall)

Chshft.c
. . .

writedocstat(__file__, docstat, runno, dcall);
refi = fopen_s(&file1, "..\\KNTBIN\\DOCSTAT2.DAT", "w+"); (L826)
assert(refi != EOF);
if( EQUAL(runno, ONE)){ (L828)
refi = fopen_s(&file1, "..\\KNTBIN\\DOCSTAT2.DA1", "w+");
assert(refi != EOF);
}

Error messages
1>..\Venext6\External Sub Functions\hospital\Chshft.c(825): error C2371: 'writedocstat': redefinition; different basic types
1>c:\vensim\hsglob.h(59): note: see declaration of 'writedocstat'
1>..\Venext6\External Sub Functions\hospital\Chshft.c(826): error C2065: 'file1': undeclared identifier
1>..\Venext6\External Sub Functions\hospital\Chshft.c(826): warning C4047: 'function': 'FILE **' differs in levels of indirection from 'int *'
1>..\Venext6\External Sub Functions\hospital\Chshft.c(826): warning C4024: 'fopen_s': different types for formal and actual parameter 1
1>..\Venext6\External Sub Functions\hospital\Chshft.c(826): error C2099: initializer is not a constant
1>..\Venext6\External Sub Functions\hospital\Chshft.c(827): error C2059: syntax error: '<parameter-list>'
1>..\Venext6\External Sub Functions\hospital\Chshft.c(828): error C2059: syntax error: 'if'
> writedocstat(__file__, docstat, runno, dcall);
What is __file__ ?
It's uncomfortably close the __FILE__ https://en.cppreference.com/w/c/preprocessor/replace

> 1>..\Venext6\External Sub Functions\hospital\Chshft.c(826): error C2065: 'file1': undeclared identifier
Undeclared identifier is such a fundamental fault in the code that it's not something you'd trigger just by changing compiler.

> assert(refi != EOF);
fopen_s doesn't return EOF.
https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/fopen-s-wfopen-s?view=msvc-160

You seem to have inherited a crock.
Topic archived. No new replies allowed.