精华内容
下载资源
问答
  • NULL实际上是一个void *的指针,然后把void *指针赋值给int *指针的时候,隐式转换成相应的类型 例如以下代码: int *i = NULL; 编译器提供的头文件如以下定义NULL:: #define NULL (void *(0)) C++中,使用0表示...

    C语言中,使用NULL表示空指针
    NULL实际上是一个void *的指针,然后把void *指针赋值给int *指针的时候,隐式转换成相应的类型
    例如以下代码:

    int *i = NULL;
    

    编译器提供的头文件如以下定义NULL::

    #define NULL (void *(0))
    

    C++中,使用0表示空指针
    C++中不能将void *类型的指针隐式转换成其他指针类型,为了解决空指针,C++中引入0来表示空指针

    C++11中,使用nullptr来表示空指针
    例如,qt5.12中,配置使用C++11,在项目的.h文件的如下语句中

    public
    explicit mainwindow(QWidget *parent = nullptr);
    

    其中,若QWidget *parent = 0则产生如题警告,使用C++11规范nullptr即可消除该警告

    展开全文
  • <p>Undefined behavior (applying zero offset to null pointer) when calling jpeg_skip_scanlines: <pre><code> jdsample.c:100:49: runtime error: applying zero offset to null pointer SUMMARY: ...
  • move zero

    2016-08-17 08:16:52
    public void moveZeroes(int[] nums) { if (nums == null || nums.length ) { return; } int p0 = 0, p1 = 0; while (p0 ) {
    public void moveZeroes(int[] nums) {
            if (nums == null || nums.length < 2) {
                return;
            }
            int p0 = 0, p1 = 0;
            while (p0 < nums.length && p1 < nums.length) {
                if (nums[p0] != 0) {
                    p0++;
                    continue;
                }
                if (nums[p1] == 0) {
                    p1++;
                    continue;
                }
                if (p1 > p0) {
                    int temp = nums[p1];
                    nums[p1] = nums[p0];
                    nums[p0] = temp;
                    p1++;
                    p0++;
                } else {
                    p1++;
                }
            }
        }

    展开全文
  • C - C++ - NULL

    2021-01-06 23:12:09
    C - C++ - NULL ...A null-pointer constant is an integral constant expression that evaluates to zero (like 0 or 0L), or the cast of such value to type void* (like (void*)0). 空指针常量是

    C - C++ - NULL

    Null pointer (空指针)
    This macro expands to a null pointer constant.
    该宏扩展为空指针常量。

    C
    A null-pointer constant is an integral constant expression that evaluates to zero (like 0 or 0L), or the cast of such value to type void* (like (void*)0).
    空指针常量是一个整数常量表达式,其值为零 (例如 0 or 0L),或者该值的类型转换为 void* 的类型 (例如 (void*)0)。

    C++98
    A null-pointer constant is an integral constant expression that evaluates to zero (such as 0 or 0L).
    空指针常量是一个整数常量表达式,其值为零 (例如 0 or 0L)。

    C++11
    A null-pointer constant is either an integral constant expression that evaluates to zero (such as 0 or 0L), or a value of type nullptr_t (such as nullptr).
    空指针常量是一个整数常量表达式,其值为零 (例如 0 or 0L),或者类型为 nullptr_t 的值 (例如 nullptr)。

    A null pointer constant can be converted to any pointer type (or pointer-to-member type), which acquires a null pointer value. This is a special value that indicates that the pointer is not pointing to any object.
    空指针常量可以转换为任何获取空指针值的 pointer type (or pointer-to-member type)。这是一个特殊的值,它指示指针没有指向任何对象。

    #define NULL /*implementation-defined*/
    

    The macro NULL is an implementation-defined null pointer constant, which may be
    宏 NULL 是实现定义的空指针常量,可为

    an integral constant expression rvalue of integer type that evaluates to zero (until C++11)
    求值为零的整数类型字面常量表达式右值
    an integer literal with value zero, or a prvalue of type std::nullptr_t (since C++11)
    零值整数字面量,或为 std::nullptr_t 类型纯右值

    A null pointer constant may be implicitly converted to any pointer type; such conversion results in the null pointer value of that type. If a null pointer constant has integer type, it may be converted to a prvalue of type std::nullptr_t.
    空指针常量能转换为任何类型;转换结果是该类型的空指针值。空指针常量可以隐式转换为任何指针类型,这种转换结果是该类型的空指针值。若空指针常量拥有整数类型,它亦可转换为 std::nullptr_t 类型纯右值。

    #define NULL 0
    //since C++11
    #define NULL nullptr
    

    In C, the macro NULL may have the type void*, but that is not allowed in C++.

    //============================================================================
    // Name        : std::strlen
    // Author      : Yongqiang Cheng
    // Version     : Version 1.0.0
    // Copyright   : Copyright (c) 2019 Yongqiang Cheng
    // Description : Hello World in C++, Ansi-style
    //============================================================================
    
    #include <iostream>
    #include <cstddef>
    
    void print(int x)
    {
    	std::cout << "print(int): " << x << '\n';
    }
    
    void print(int *x)
    {
    	if (!x)
    	{
    		std::cout << "print(int*): null\n";
    	}
    	else
    	{
    		std::cout << "print(int*): " << *x << '\n';
    	}
    }
    
    int main()
    {
    	int *x{ NULL };
    	print(x); // calls print(int*) because x has type int*
    	print(0); // calls print(int) because 0 is an integer literal
    	print(NULL); // likely calls print(int), although we probably wanted print(int*)
    
    	return 0;
    }
    
    print(int*): null
    print(int): 0
    print(int): 0
    请按任意键继续. . .
    

    References

    http://www.cplusplus.com/reference/cstdlib/NULL/
    https://en.cppreference.com/w/c/types/NULL
    https://en.cppreference.com/w/cpp/types/NULL
    https://zh.cppreference.com/w/c/types/NULL
    https://www.learncpp.com/cpp-tutorial/null-pointers/

    展开全文
  • 0-NULL-nullptr

    2019-09-22 00:36:03
    A null-pointer constant is an integral constant expression that evaluates to zero (like 0 or 0L), or the cast of such value to type void* (like (void*)0). In C++98 A null-pointer consta...

    NULL

    In C

    A null-pointer constant is an integral constant expression that evaluates to zero (like 0 or 0L), or the cast of such value to type void* (like (void*)0).

    In C++98

    A null-pointer constant is an integral constant expression that evaluates to zero (such as 0 or 0L).

    In C++11

    A null-pointer constant is either an integral constant expression that evaluates to zero (such as 0 or 0L), or a value of type nullptr_t (such as nullptr).

    From the description of cpluscplus reference, we can see that NULL's definition is compiler dependent. In this blog, I only discuss the behavior of gcc in linux operating system.

    // file test.c
    #include<stdio.h>
    
    void func(int* p) {
        if (p) *p = 1;
    }
    
    int main()
    {
        int* p = 0;//NULL;
        func(NULL);
    
        return 0;
    }

    use gcc to see what's NULL is:

    gcc -E test.c | less

    result:

    # 2 "test.c" 2
    
    void func(int* p) {
        if (p) *p = 1;
    }
    
    int main()
    {
        int* p = 0;
        func(((void *)0));
    
        return 0;
    }

    we can see that in C, NULL is (void*)0;

    In C++

    #include<iostream>
    
    void func(int* p) {
        if (p) *p = 1;
    }
    
    int main()
    {
        int* p = 0;//NULL;
        func(NULL);
        std::cout << p << std::endl;
    
        return 0;
    }

    result:

    void func(int* p) {
        if (p) *p = 1;
    }
    
    int main()
    {
        int* p = 0;
        func(__null);
        std::cout << p << std::endl;
    
        return 0;
    }

    it's __null, a integral constant expression.

    The only change that might affect people is the type of NULL: while it is required to be a macro, the definition of that macro is not allowed to be (void*)0, which is often used in C.
    
    For g++, NULL is #define'd to be __null, a magic keyword extension of g++.
    
    The biggest problem of #defining NULL to be something like “0L” is that the compiler will view that as a long integer before it views it as a pointer, so overloading won't do what you expect. (This is why g++ has a magic extension, so that NULL is always a pointer.)

    nullptr

    typedef decltype(nullptr) nullptr_t;
    Null pointer type (C++)
    Type of the null pointer constant nullptr.
    
    This type can only take one value: nullptr, which when converted to a pointer type takes the proper null pointer value.
    
    Even though nullptr_t it is not a keyword, it identifies a distinct fundamental type: the type of nullptr. As such, it participates in overload resolution as a different type.
    
    This type is only defined for C++ (since C++11).

    转载于:https://www.cnblogs.com/keviwu/p/7489876.html

    展开全文
  • TaskLauncher zero_size_launcher(ZERO_SIZE_TASK_ID, TaskArgument(NULL,0)); zero_size_launcher.add_region_requirement( RegionRequirement(structured_lr, WRITE_DISCARD, EXCLUSIVE, structured_lr)); ...
  • null) { #if USE_WINDOWS_HEAP Heap.HeapDestroy(_heapPtr); #else Marshal.FreeHGlobal(_memoryPtr); #endif } } } } #if USE_WINDOWS_HEAP public class Heap { [DllImport("kernel32.dll", ...
  • <p>In StarPU we sometimes have data transfers of zero bytes (data used for synchronization only). It happens that it makes simgrid crash here: <h1>0 0x00007ffff42278e0 in Action::setData(void*) () ...
  • fontCollection.AddMemoryFont(IntPtr.Zero, 100)); } } [Theory] [InlineData(0)] [InlineData(-1)] public void AddMemoryFont_InvalidLength_ThrowsArgumentException(int length) { using (var ...
  • Warning[Pe186]: pointless comparison of unsigned integer with zero typedef enum { PRO_NULL = 0, PRO_TYPE_X, PRO_TYPE_Y, PRO_TYPE_Z, PRO_MAX_TYPE, }PRO_TYPE; void fun(char *pData) { PRO_TY...
  • zeroCopy_零拷贝_java

    2020-11-02 23:25:18
    /** * 文件拷贝 * @param srcFile * @param destFile */ public static void ... if (srcFile == null || destFile == null) { return; } try { FileChannel source = new FileInputStream(srcFile).getC.
  • zero ICE快速入门java版

    2017-09-20 10:40:18
    zero ICE快速入门文档, ice是最优秀的rpc框架。 4、开发服务端代码如下 步骤一:编写Servant类即带有Disp的存根文件也就是说继承_HelloWorldDisp 这个类,这个类是个抽象类定义如下: public abstract class _...
  • <p>I also have to define another version for zero arguments ( or could check explicitely if it is a null node, which mostly is even more complicated) <pre><code> (def x (macro intern (void) (qq a))) ...
  • , in many messages NULL is being used as a more general term for nothing or zero. I decided to revert these message changes and not alter any user-visible output. - regex find: ".<em>?nullptr....
  • char *api_get_nick(void)

    2020-12-05 12:54:05
    <div><p>The code should be checking for len variable greater than zero. <p>when len == 0 you malloc 1 byte, name will not be null, but will likely be corrupted.</p><p>该提问来源于开源项目&#...
  • <p>I believe when building using clang4, that NULL is not considered a nullptr type but just zero. <p>I suspect the fix is rather straight forward, and just provide a StringFrom(nullptr_t) if we'...
  • public void onSelectedFilePaths(String[] files) { if(files == null){ utility.doNothihng(); }else if(files.length == 1){ String sPathFolder = files[0]; } } }); fd.show(); ...
  • It resets the valuetype (struct) to its default zero-ed value (default(T)). <p>This behaviour is documented here: ...
  • <p>From my "limited" knowledge of C, <code>NULL</code> is (void *)0</code>. Now, my guess is that <code>PHP</code> "magic" type casting is somehow casting <code>void *</code> to <code>int *</code>?!! ...
  • --- /dev/null +++ b/test/CodeGen/AVR/umul.with.overflow.i16-bug.ll @@ -0,0 +1,39 @@ +; RUN: llc -O1 < %s -march=avr | FileCheck %s + +target data...
  • private void doDtest() { String url = " https://docs.google.com/feeds/download/documents/export/Export?id=12DquFymgKDTeIKkHa-OQuO5V-pHz-1v5EKAxaQPwQm0&exportFormat=html&format...
  • * NullPointerException if timeUnit is null * IllegalArgumentException if durationAmount is less than 0 or a TimeUnit less than milliseconds is specified */ public Duration(TimeUnit timeUnit, long ...
  • m trying to use your solution to get list of jobs or findJobByTag, but i get zero size <p>could you review my code? after 4 days i cant resolve this problem, thanks in advance <pre><code> public class...
  • public void home(ReferenceHead head) throws Exception { // Home is sent with an infinite timeout since it's tough to tell how long it will // take. String command = getCommand(null, ...
  • [Id] INT NOT NULL PRIMARY KEY, [Value1] SMALLINT NOT NULL DEFAULT ((0)), [Value2] SMALLINT NOT NULL DEFAULT ((1)) ) </code></pre> <p>` <h3>Expected (as with "from Database") <pre><code...
  • ].isNull()) {" + +// To Do Check whether all laps start with Zero +// Is there a function for all member of an array rather than be iterative + + bool sumstartzero = true; ...
  • <p><code>global::ObjCRuntime.Messaging.void_objc_msgSend_IntPtr_IntPtr_nuint_IntPtr (this.Handle, Selector.GetHandle ("connect:toConnectionPoints:fromBus:format:"), sourceNode.Handle, nsa_...
  • null; try { var filePath = ConfigurationManager.AppSettings["PuppeterSharpBrowserFetcherLocalChromium"].ToString(); int timeOut = 0; if (int.TryParse(ConfigurationManager....
  • 更新Xcode 9后原来的项目报错  之前忘了是改什么了虽然不报错,但是运行后连不上网。 今天试了把0 改为 (char *)0 可以了了 ,又试了其他的 (void *)NULL , (void *)0, 都可以了。
  • null || delay.getValue() <= 0) { // No delay so write response immediately writeAndCloseSocket(ctx, request, response); } else { // Schedule writing of response after delay ctx.executor...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 718
精华内容 287
关键字:

nullvoidzero