1ms Faster
Home
  • Program

    • Lean in C++
  • Perfromance Engineering

    • [>>>>>]
  • Reading Note

    • [>>>>>]
  • ComputeArch

    • [_]
  • Compiler

    • [_]
  • System

    • [_]
Authoring
  • Categories
  • Tags
GitHub (opens new window)

Quincy Jet

We are.
Home
  • Program

    • Lean in C++
  • Perfromance Engineering

    • [>>>>>]
  • Reading Note

    • [>>>>>]
  • ComputeArch

    • [_]
  • Compiler

    • [_]
  • System

    • [_]
Authoring
  • Categories
  • Tags
GitHub (opens new window)
  • Lean in c++

    • Lean in C++
    • Phase_0:Glimpse

      • C++ Glimpse
      • type cast
      • typedef
      • class vs. typename
      • const
      • extern
      • pointer
        • 引用与指针那些事
        • 函数指针和指针函数
      • static
      • volatile
      • inline
      • assert
      • void
      • __global__
  • Performance Engineering

  • Misc

  • Reading Notes

  • Wiki
  • Lean in c++
  • Phase_0:Glimpse
Quincy Jet
2022-06-27
Content

pointer

# 引用与指针那些事 (opens new window)

# 函数指针和指针函数

#include <iostream>
using namespace std;
/*! \brief Possible kinds of TypeVars. */
enum TypeKind {

 kType = 0,
 /*! \brief Template variable in shape expression. */
 kShapeVar = 1,
 kBaseType = 2,
 kConstraint = 4,
 kAdtHandle = 5,
 kTypeData = 6
};

union TypeValue {
 char c;
 unsigned char uc;
 long l;
};

const double* f1(const double arr[], int n) { return arr; }
const double* f2(const double arr[], int n) { return arr + 1; }
const double* f3(const double* arr, int n) { return arr + 2; }

int main(int argc, char* argv[]) {
 TypeKind a = kShapeVar;
 TypeValue b;
 b.c = 'L';
 cout << "test for union:b.c " << b.c << endl;

 b.l = 1234;
 cout << "test for union:b.l " << b.l << endl;
 cout << "test for union:b.c " << b.c << endl;

 double at[3] = {12.1, 3.4, 4.5};
 const double* (*pfunc)(const double*, int) = f1;
 cout << "test for function pointer: Point1: " << *pfunc(at, 3) << endl;

 const double* (*pfunc1[3])(const double*, int) = {f1, f2, f3};
 cout << "test for function pointer: Point1: " << *pfunc1[2](at, 3) << endl;
 cout << "test for function pointer: Point12: " << *pfunc1[0](at, 3) << endl;
 cout << "test for function pointer: Point1: " << *((*pfunc1[2])(at, 3)) << endl;
 cout << "test for enum: " << a << endl;

 cout << "hello word" << endl;



 cout << "test for singleton";

 return 0;

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
Last updated: 2023/03/11, 03:13:10
extern
static

← extern static→

Copyright © 2017-2023 Quincy Jet | MIT License
  • Auto
  • Light
  • Dark
  • Read