CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Feb 2015
    Posts
    4

    Trouble with C And Windows Runtime

    I am a very experienced C programmer. I am getting into Windows 8.1 Store apps.

    As we all know, when dealing with C on Visual Studio, the best best is to correctly name your source files as .c and not .cpp

    The problem is that doing so in metro world gives lots of 'error D8048: cannot compile C file X with the /ZW option' errors. It is my understanding that I need this flag for the correct runtime.

    I'd like to compile some legacy code with lots of malloc commands in, so renaming the files to .cpp is not practical unless I can turn off the resulting errors about casting from void*

    Any idea how I can go about writing C for store apps?

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: Trouble with C And Windows Runtime

    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  3. #3
    Join Date
    Feb 2015
    Posts
    4

    Re: Trouble with C And Windows Runtime

    Following the links advice, I started encountering varied problems and errors in header files I was not personally including directly. Some regression has clearly taken place in MSVS.

    For now, I am using awk scripts to butcher my c into cpp. It is a shame that cpp lacks many convenient features such as named structure element initialization. I am not prepared to write cpp, I will just have to stick to the common subset for the short term.

  4. #4
    Join Date
    Feb 2015
    Posts
    4

    Re: Trouble with C And Windows Runtime

    Thanks for the suggestion tho'. It was good to try.

  5. #5
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: Trouble with C And Windows Runtime

    cpp lacks many convenient features such as named structure element initialization
    What can you do in c that you can't in c++?
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: Trouble with C And Windows Runtime

    Quote Originally Posted by 2kaud View Post
    What can you do in c that you can't in c++?
    Good question!
    There are some very important thigs available in C++ (OOP for example) that are not available in C.
    But vice versa?
    Victor Nijegorodov

  7. #7
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Trouble with C And Windows Runtime

    Quote Originally Posted by VictorN View Post
    Good question!
    There are some very important thigs available in C++ (OOP for example) that are not available in C.
    But vice versa?
    If you aren't on board with c++ at this point, you'll likely never be.

  8. #8

    Re: Trouble with C And Windows Runtime

    The error message is exactly what it says it is - VC++ does not support C++/CX extensions - enabled with /ZW compiler switch - in files compiled as C (which kinda makes sense, since those extensions are object-oriented).

    The reason why you're seeing this is that, by default, all files in a Metro C++ project are compiled with /ZW. Unfortunately, this also applies to .c files, even though it doesn't actually work for them. What you need is to disable the extensions selectively for those files. You can do so via right-click -> Properties on a file or a selection of files in Solution Explorer. In the Property Pages dialog, navigate to C/C++ -> General, and look for "Enable Windows Run Time Extensions".
    Last edited by bestellen; September 15th, 2015 at 04:16 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured