English 中文(简体)
法典C还是C++?
原标题:Is the code C or C++?
  • 时间:2012-04-07 12:09:59
  •  标签:
  • c++
  • c

我知道下文使用的代码为C,但我在2008年视力演播室把它作为C++方案写成,并做罚款(作为C++予以节省)。 然而,该方案载于C法典,正确吗? (还是?)

因此,当我试图在视力演播室内将其编为C(Go to-> Property of file ->c/c++ ->Advanced -> Compile as -> change to Compile as C Code 然后,我发现许多错误,其主要错误不承认《劳动法》。 因此,我想到的是: 是C 还是C++ 代码,如果是C ,为什么在我修改汇编C码时没有工作?

#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
#include <strsafe.h>
#include <direct.h>
#include <string.h>
#include <conio.h>

int main(VOID)
{
    STARTUPINFO si;
    PROCESS_INFORMATION pi;

    //allocate memory
    ZeroMemory(&si, sizeof(si));
    si.cb = sizeof(si);
    ZeroMemory(&pi, sizeof(pi));


    //create child process
    if (!CreateProcess(NULL,
                L"C:\Windows\Notepad.exe",
                NULL,
                NULL,
                FALSE,
                0,
                NULL,
                NULL,
                &si,
                &pi))
    {
        fprintf(stderr, "create process failed");

        return -1;
    }

    //parent waits for child to complete
    WaitForSingleObject(pi.hProcess, INFINITE);

    printf("Child Complete");

    //close handle
    CloseHandle(pi.hProcess);
    CloseHandle(pi.hthread);

}  
问题回答

www.un.org/spanish/ecosoc 简明汇编为C。 唯一错误是由<代码>CloseHandle(pi.hthread)引发的,因为它不是<代码>的成员。 PROCESS_INFORMATION。 页: 1

但大多数C++汇编者能够汇编C码。 标题<代码>conio.h不是标准C的一部分,因此你可能想避免这种情况。

LPSTR在窗口.h中界定,并且由于你已经包括进来,因此不应有任何错误。 它是:

typedef char* PSTR, *LPSTR; 

对于您的法典中的其他类型变数,您必须检查其负责人。 Try including Winbase.h

从你给我们提供的情况看,它是否有效,因为你正在使用非标准头盔和宏观产品。 但我可以想象,可以有宏观定义,将这种定义变成C法典。

If 是C的,对C++来说不是那么好,也不是那么好。 这两种语文都能够初步确定变量,但你的代码没有使用这些变量。 特别是在C(和C++的POD)有初始变数。 认为这里的两种宏观方法都扩大到:

STARTUPINFO si = { 0 };
PROCESS_INFORMATION pi = { 0 };

如果你有一位符合《公约》规定的汇编员,那么第一名汇编员会更好。

STARTUPINFO si = { .cb = sizeof si };

If for some reason you d need a function to zero out a whole block of memory, better use the standard function memset for that. But if you use the correct initializers in C (or constructors in C++) you should rarely need that explicitly.





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签