[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference turris::c_plus_plus

Title:C++
Notice:Read 1.* and use keywords (e.g. SHOW KEY/FULL KIT_CXX_VAX_VMS)
Moderator:DECCXX::AMARTIN
Created:Fri Nov 06 1987
Last Modified:Thu Jun 05 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:3604
Total number of notes:18242

3538.0. "compilation problem with #define directive" by TUXEDO::LU () Tue Apr 15 1997 18:20

This problem has something to do with #define preprocessor directive.
What follows is a snippet of code that can be used to reproduce it.

BTW, I am running DEC C++ V5.5-004 on Digital Unix V4.0.

% cat foo.cxx
#include <time.h>

void foo()
{
    time_t clock;
    struct tm res;

    localtime_r(&clock, &res);
}
% cxx -c foo.cxx
cxx: Error: foo.cxx, line 8: In this statement, "_Plocaltime_r" is not declared.

The same code compiles just fine with cc. Any insight would be appreciated.

-James

T.RTitleUserPersonal
Name
DateLines
3538.1problem is in /usr/include/time.h header fileDECC::J_WARDTue Apr 15 1997 18:4847
It looks like the culprit is in /usr/include/time.h:

#ifdef  __DECC
#pragma extern_prefix "_P"
#else
#define asctime_r(__a,__b)      _Pasctime_r(__a,__b)
#define ctime_r(__a,__b)        _Pctime_r(__a,__b)
#define gmtime_r(__a,__b)       _Pgmtime_r(__a,__b)
#define localtime_r(__a,__b)    _Plocaltime_r(__a,__b)
#endif  /* __DECC */
#endif  /* !_LIBC_POLLUTION_H_ */
extern char *asctime_r __((const struct tm *, char *));
extern char *ctime_r __((const time_t *, char *));
extern struct tm *gmtime_r __((const time_t *, struct tm *));
extern struct tm *localtime_r __((const time_t *, struct tm *));

So the localtime_r is being macroized to _Plocaltime_r
with no corresponding prototype declared.

So I think the maintainers of time.h should be notified (see
CXXC_BUGS note 3535.3 for instructions). For now they
can workaround this problem by adding the declarations to
the code directly, i.e.:

// foo3.cxx
#include <time.h>

// add these prototypes to workaround problem in time.h
extern "C" {
extern char * _Pasctime_r __((const struct tm *, char *));
extern char * _Pctime_r __((const time_t *, char *));
extern struct tm *_Pgmtime_r __((const time_t *, struct tm *));
extern struct tm *_Plocaltime_r __((const time_t *, struct tm *));
}

void foo()
{
    time_t clock;
    struct tm res;

    localtime_r(&clock, &res);
}

main() {}


3538.2Digital UNIX problem. Fixed in V4.0BDECC::SULLIVANJeff SullivanTue Apr 15 1997 19:0227
This is a problem in the /usr/include/time.h header file, that has since been
fixed in Digital UNIX V4.0B.

Here is the diff:
diff time.h /usr/include/time.h
143,146c143,146
< extern char * __P_C(asctime_r) __((const struct tm *, char *));
< extern char * __P_C(ctime_r) __((const time_t *, char *));
< extern struct tm * __P_C(gmtime_r) __((const time_t *, struct tm *));
< extern struct tm * __P_C(localtime_r) __((const time_t *, struct tm *));
---
> extern char *asctime_r __((const struct tm *, char *));
> extern char *ctime_r __((const time_t *, char *));
> extern struct tm *gmtime_r __((const time_t *, struct tm *));
> extern struct tm *localtime_r __((const time_t *, struct tm *));

The first is the V4.0B file with the fix.

You could either upgrade to V4.0B or look for a patch at
http://www.zk3.dec.com/dupatchwww/

Or you could "patch" the file yourself, with the above edit.


This is not a C++ compiler problem.

-Jeff
3538.3Which version is which (Digital UNIX) ?DECC::SULLIVANJeff SullivanTue Apr 15 1997 19:1432
Note that all versions of Digital UNIX V4.0* will report V4.0 when using
"uname -r". For example:

% uname -a
OSF1 isaiah.zk3.dec.com V4.0 386 alpha

% uname -a
OSF1 quarry.zk3.dec.com V4.0 564 alpha

The first contained the time.h bug, the second had the fix.
As you can see, V4.0 doesn't always equal V4.0!
(The first is V4.0, the second V4.0B)

One good resource that I found is this table of UNIX revisions at

  http://www.zk3.dec.com/unix_versions.html

For the V4.0 family, here is the pertinent info:

  4.0     Platinum         pt          12 Jun 1996  386     OSF400   11
  4.0a    PTA              pta         12 Sep 1996  464     OSF405   9
  4.0b    PTB              ptb         13 Dec 1996  564     OSF410   14
  4.0c    PT-HW1           pthw1       est 4/97                      13,
  4.x     PTmin            ptc         est 10/97                     12
  4.x     Steel            steel       est Q1CY98                    10

Note that to distinguish V4.0 from V4.0a from V4.0b, you need to look at
the rev number in addition to the version number.

-Jeff


3538.4Thanks for the replies.TUXEDO::LUTue Apr 15 1997 21:134
I'll patch my code locally so it can be moved around among several DU 4.0a machines that we
have here unless there is a compelling reason to do the upgrade.

-James