日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) >

在C语言中malloc怎么声明,问下关于malloc的声明问题

發(fā)布時(shí)間:2023/12/19 53 豆豆
生活随笔 收集整理的這篇文章主要介紹了 在C语言中malloc怎么声明,问下关于malloc的声明问题 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

該樓層疑似違規(guī)已被系統(tǒng)折疊?隱藏此樓查看此樓

Advantages to casting

Including the cast allows a program or function to compile as C++.

The cast allows for pre-1989 versions of malloc that originally returned a char *.[8]

Casting can help the developer identify inconsistencies in type sizing should the destination pointer type change, particularly if the pointer is declared far from the malloc() call.[edit]Disadvantages to casting

Under the ANSI C standard, the cast is redundant.

Adding the cast may mask failure to include the header stdlib.h, in which the prototype for malloc is found.[8][9] In the absence of a prototype for malloc, the standard requires that the C compiler assumemalloc returns an int. If there is no cast, a warning is issued when this integer is assigned to the pointer; however, with the cast, this warning is not produced, hiding a bug. On certain architectures and data models (such as LP64 on 64-bit systems, where long and pointers are 64-bit and int is 32-bit), this error can actually result in undefined behaviour, as the implicitly declared malloc returns a 32-bit value whereas the actually defined function returns a 64-bit value. Depending on calling conventions and memory layout, this may result in stack smashing. This issue is less likely to go unnoticed in modern compilers, as they uniformly produce warnings that an undeclared function has been used, so a warning will still appear. For example, GCC's default behaviour is to show a warning that reads "incompatible implicit declaration of built-in function" regardless of whether the cast is present or not.

If the type of the pointer is changed, one must fix all code lines where malloc was called and cast (unless it was cast to a typedef).

總結(jié)

以上是生活随笔為你收集整理的在C语言中malloc怎么声明,问下关于malloc的声明问题的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。