指针与数组
c/c++ 大多数情况下对待这两个的方式一样,导致区别变得模糊。 但是如果循环处理时,还是有性能的区别: The first program uses the expression (array[index] != 0). This requires the compiler to generate an index operation, which takes longer than a simple pointer de-reference: ((*array_ptr) != 0). The expression at the end of this program, array_ptr - array, computes how far array_ptr is into the array.
int array[10] = {4, 5, 8, 9, 8, 1, 0, 1, 9, 3};
int *array_ptr;
main()
{
array_ptr = array;
while ((*array_ptr) != 0)
++array_ptr;
index = 0;
while (array[index] != 0)
++index;
cout << "Number of elements before zero <<
(array_ptr - array) << '\n';
return (0);
}
类型描述
编译器总结
看到这个链接,编译器还有好多产品 https://www.openmp.org/resources/openmp-compilers-tools/
列表:ARM/AMD/Intel/富士通/HPE/IBM/Apple/NVIDIA/Oracle, 都有自己的编译器。clang/Flang/gcc/
语法总结
goto
结构初始化
designated initializer),是一个ISO标准
++ 和 后++
The prefix form ++variable is preferred over the suffix form variable ++ because it allows the compiler to generate slightly simpler code. 会产生side effect的操作符。
packed
virtual
The virtual keyword identifies a member function that can be overridden by a member function in the derived class. If we are using a derived class, then C++ will look for members in the derived class and then in the base class, in that order. If we are using a base class variable (even if the actual instance is a derived class), then C++ will search only the base class for the member function. The exception is when the base class defines a virtual function. In this case, the derived class is searched and then the base class. The “= 0” tells C++ that these member functions are pure virtual functions. That is, they can never be called directly. Any class containing one or more pure virtual functions is called an abstract class.
|