- 博客(9)
- 资源 (2)
- 问答 (2)
- 收藏
- 关注
原创 C语言 计算数组长度
第一种情况一维数组int a[] = {1, 2, 3, 4, 5, 6};int len = sizeof(a) / sizeof(a[0]);多维数组int a[][3]={1, 2, 3, 4, 5, 6, 7};int row = sizeof(a) / sizeof(a[0]);int col = sizeof(a[0]) / sizeof(a[0][0]);二维数组是一维数组,其中每个元素是一维数组。同理,三维数组是一维数组,其中每个元素是二维数组;二维数组是一维
2021-06-21 21:29:08 1344
原创 保护宏
参考链接:C++里面保护宏的用法Clean C++:头文件保护宏C++核心准则:ES.33:如果必须使用宏定义,命名要有唯一性第一篇介绍了防止头文件重复包含的两种方法:保护宏;特定编译器命令 #pragma once 。第二篇来自书籍《Clean C++》,介绍了保护宏的三种命名方法。第三篇来自C++核心准则,指出:ES.33: If you must use macros, give them unique namesReason: Macros do not obey scope ru
2020-07-01 17:48:06 510
转载 Feature Test Macros
1.3.4 Feature Test Macros原文链接 1.3.4 Feature Test Macros。The exact set of features available when you compile a source file is controlled by which feature test macros you define.If you compile your programs using ‘gcc -ansi’, you get only the ISO C libra
2020-07-01 12:19:16 546
原创 C PUZZLE中的一道题
如下程序设计功能为打印20个负号,但没能实现。通过改变一个字符修复一个破碎的循环。已知有三种解法。 #include <stdio.h> int main() { int i; int n = 20; for( i = 0; i < n; i-- ) printf("-"); return 0; ...
2019-11-13 21:47:10 151
原创 C PUZZLES中的一道题
题目:The following C program segfaults of IA-64, but works fine on IA-32.int main() { int* p; p = (int*)malloc(sizeof(int)); *p = 10; return 0; } Why does it happen so?解答:...
2019-11-06 20:18:31 123
转载 内存对齐宏的数学解释
内存对齐宏的数学解释博主表示没看懂?-)有网友发帖问:#define _INTSIZEOF(n) ((sizeof(n)+sizeof(int)-1)&~(sizeof(int) - 1) )说能够在某些系统中内存对齐.(估计是得到一个2 或者4的整数倍)这个好象就是(x+3)&~3这样就能满足对齐了吗?请从数学上给说说.谢谢有网友发帖答:对于两个正整数 ...
2019-10-27 15:07:30 194
转载 转:Catching Integer Overflows in C
转:Catching Integer Overflows in CUpdate 20150422: clang and gcc 5 have builtins now for this, look for __builtin_add_overflow and __builtin_mul_overflow in the documentation. That makes these macros ...
2019-10-27 15:00:28 342
原创 记一个编译错误
#include<stdio.h>int main(){int a=1;switch(a){case 1:int b=20;printf(“b is %d\n”,b);break;default:printf(“b is %d\n”,b);break;}return 0;}gcc编译报错,信息如下:error: a label can only be p...
2019-09-07 21:52:17 290 2
转载 C语言宏替换问题
转载:关于C里面宏替换的问题 http://blog.chinaunix.net/uid-27714502-id-3461678.html先看一个经典的面试题:#include#define f(a,b) a##b#define g(a) #a#define h(a) g(a)int main(){printf("%s\n", h(f(1,2)));printf("%s\n",...
2019-08-17 17:29:57 1652
Leetcode56 合并区间, 线上执行时报heap-buffer-overflow
2021-09-11
能举个数组名作左值的例子吗?
2021-06-26
TA创建的收藏夹 TA关注的收藏夹
TA关注的人