Subject: Re: bug#9960: Compiling Emacs trunk with MSVC

From: Eli Zaretskii <[email-masked]>
Date: Sun, 06 Nov 2011 01:37:44 -0400

> From: Christoph Scholtes <[email-masked]>
> Cc: [email-masked]
> Date: Sat, 05 Nov 2011 16:23:40 -0600
> 
> Eli Zaretskii <[email-masked]> writes:
> 
> > That comes from Fabrice, assuming that removing `static' doesn't help.
> 
> No, it does not.
> 
> > Does it fail even if you take (1 << 3) in one more level of
> > parentheses?
> 
> Yes.
> 
> > What about an intermediate macro, as in
> >
> >  #define FOO (1 << GCTYPEBITS)
> >  static int __declspec(align(FOO)) test = 1;
> >
> > ?
> 
> Not working. I tried all of these cases in my simple example. It does
> seem to like the shift operator.

I guess Fabrice will have to figure this out.  I'm puzzled how it
worked for him a year ago.

> > Does this go away if you add "#define snprintf _snprintf" to
> > src/s/ms-w32.h, for MSVC only?
> 
> Yes.
> 
> > These are because xdisp.c defines window_box_right `inline'.  (This is
> > an optimized build, right? if not, does it mean that MSVC inlines
> > functions even for a non-optimized builds?)  I would suggest to make
> > that `inline' conditional on _MSC_VER being undefined.
> 
> That worked.
> 
> > Add "#define strtoimax _strtoi64" to src/s/ms-w32.h, conditioned on
> > _MSC_VER.
> 
> Worked.

Please install the 1st and the 3rd of these 3.  I'm about to start a
discussion regarding the 2nd one.

> > Make this (from src/s/ms-w32.h):
> >
> >   #if !defined (_MSC_VER) || (_MSC_VER < 1400)
> >   #define tzname    _tzname
> >
> > be defined unconditionally.  (But leave the "utime" part under the
> > same condition it is today.)
> 
> This is a problem. The ensuing error is:
> 
> C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\INCLUDE\time.h(281) : erro
> r C2090: function returns array
> 
> >From time.h:
> _CRT_INSECURE_DEPRECATE_GLOBALS(_get_tzname) _CRTIMP extern char * tzname[2];

How about using _get_tzname to set up our own private array akin to
tzname[]?  Here's the plan:

 . in src/s/ms-w32.h, "#define tzname msvc_tzname" (for _MSC_VER >= 1400)

 . in w32.c:sys_localtime, when _MSC_VER >= 1400, call _get_tzname
   twice to populate tzname[] with 2 values as expected

 . reinstate HAVE_TZNAME for MSVC

Does this work, i.e. link without errors?

Thanks.