Decision Optimization

 View Only
  • 1.  Visual Studio character encoding setting and CPLEX examples

    Posted Sat August 15, 2020 12:49 AM
    Edited by System Test Fri January 20, 2023 04:50 PM
    Hello,

    According to:

    https://docs.microsoft.com/en-us/cpp/text/unicode-and-mbcs?view=vs-2019#:~:text=Unicode%20is%20a%2016%2Dbit,of%201%20or%202%20bytes.

    "When run on an MBCS-enabled version of the Windows operating system, the Visual C++ development system - including the integrated source code editor, debugger, and command-line tools - is completely MBCS-enabled."

    On my machine, what this seems to mean is that whenever a new project is created in Visual Studio C++, the character set property (Right click on Project in Visual Studio, -> Configuration Properties -> Advanced -> Advanced Properties -> Character Set seems to be default and automatically set to "Use Multibyte Character Set"

    However, the .vcxproj distributed with CPLEX examples seems to recommend using unicode. For instance, admipex1.vcxproj has the following line:

    <CharacterSet>Unicode</CharacterSet>

    What this seems to mean is that on the command line, _UNICODE and UNICODE are defined. However, since the default Visual Studio project seems to import the Multibyte charater set property sheet, _MBCS is also defined.

    That is, defining _UNICODE does NOT seem to undefine _MBCS.

    The following microsoft document: https://docs.microsoft.com/en-us/cpp/atl-mfc-shared/unicode-and-multibyte-character-set-mbcs-support?view=vs-2019#:~:text=The%20symbols%20_MBCS%20and%20_UNICODE%20are%20mutually%20exclusive.&text=To%20enable%20both%20MBCS%20and,char*%20or%20const%20wchar_t*%20.

    indicates that _MBCS and _UNICODE are mutually exclusive.

    That is, on the command line, you cannot have both /D "_UNICODE" and /D "_MBCS"

    The only way out for me was to create a new property sheet in visual studio where I undefed _MBCS. The content of this .props file was:

    <?xml version="1.0" encoding="utf-8"?>
    <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <ImportGroup Label="PropertySheets" />
    <PropertyGroup Label="UserMacros" />
    <PropertyGroup />
    <ItemDefinitionGroup>
    <ClCompile>
    <UndefinePreprocessorDefinitions>_MBCS</UndefinePreprocessorDefinitions>
    </ClCompile>
    </ItemDefinitionGroup>
    <ItemGroup />
    </Project>

    Also, this property sheet was inserted last (since Visual Studio evaluates property sheets in the order where a later setting overrides a previous setting of an earlier property sheet.

    ​I have few questions:

    (a)Can it be clarified that CPLEX does NOT recommend defining both /D "_UNICODE" and /D "_MBCS" ?

    (b)Since the default in Visual Studio seems to be defining _MBCS, is there any overriding reason why CPLEX distributes examples where _UNICODE needs to be defined?

    (c)Does this setting one way or the other really matter in speed of CPLEX routines' running?

    Thanks.

    ------------------------------
    CPLEX User
    ------------------------------
    #DecisionOptimization


  • 2.  RE: Visual Studio character encoding setting and CPLEX examples

    Posted Mon August 17, 2020 01:32 AM
    (a) CPLEX does not advise against official recommendations. If they say that the two macros should not be used simultaneously, then you should indeed avoid doing that.
    (b) CPLEX by default assumes UTF-8 internally. So strings you pass to CPLEX (and that come from your source files) should be encoded in UTF-8. I don't know details about this other character set and its encoding. If the encoding does not default to UTF-8 then you may have to adapt the CPX_PARAM_APIENCODING parameter.
    (c) It should not affect CPLEX's speed. Internally, a string is to CPLEX some sort of (multi-)NUL-terminated byte sequence that is only interpreted during output or copying. These operations are not performed frequently, so they should not produce a bottleneck.

    ------------------------------
    Daniel Junglas
    ------------------------------