Home > Mobile >  C 20 Modules std.ixx STL Static/Global Scope References
C 20 Modules std.ixx STL Static/Global Scope References

Time:01-23

Following instructions by Microsoft, I couldn't get the std module to build and not have a versioning error, so I went ahead and just added the file:

C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.35.32213\modules\std.ixx

to my project and I import it into my module interface files. My only issue is I can't access ::localtime_s because it is one of the static-inline/global functions not in the std namespace. Including <time.h> in the global module space creates issues with macro redefinitions. Is there something I am missing?

export module MyModule;

import std;

export namespace nspace1 {

    void TimeFunction();

}

namespace nspace1 {

    void TimeFunction()
    {
        std::time_t t = std::time(nullptr);

        std::tm* now{};

        void* result = ::localtime_s(now, &t); <== dne

    }

}

The intellisense error is it is not found in the global space which makes sense for localtime_s because it is static, but _localtime64_s is just global and it says the same thing. Dropping the double colons just changes the error message to cannot be found.

CodePudding user response:

The following code builds ok on my machine.

(Version 17.5.0 Preview 3.0)

import std; is a C 23 feature. I hope vendor support is getting better.

module;

#include <time.h>

export module MyModule;

import std;

export namespace nspace1 {

    void TimeFunction();

}

namespace nspace1 {

    void TimeFunction()
    {
        std::time_t t = std::time(nullptr);

        std::tm* now{};

        auto result = ::localtime_s(now, &t);
        //auto result = localtime_s(now, &t); // ok, too

    }
}
  • Related