区别:1、C语言源文件的扩展名是“.h”和“.c”,Go语言源文件的扩展名是“.go”。2、C语言中通过文件来管理代码,Go语言中通过包来管理代码。3、C语言中一共有32个关键字,Go语言中一共有25个关键字。
本教程操作环境:windows7系统、c99&&GO 1.18版本、Dell G3电脑。
文件扩展名 | 源类型 |
---|---|
.h | 头文件,存放代码声明 |
.c | C语言源文件,存放代码实现 |
文件扩展名 | 源类型 |
---|---|
.go | Go语言源文件,存放代码实现 |
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
---|---|---|---|---|---|---|---|
if | else | switch | case | default | break | return | goto |
do | while | for | continue | typedef | struct | enum | union |
char | short | int | long | float | double | void | sizeof |
signed | unsigned | const | auto | register | static | extern | volatile |
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
---|---|---|---|---|---|---|---|
if | else | switch | case | default | break | return | goto |
fallthrough | for | continue | type | struct | var | const | map |
func | interface | range | import | package | defer | go | select |
chan |
C语言数据类型
Go语言数据类型
类型 | 32位编译器 | 64位编译器 |
---|---|---|
char | 1 | 1 |
int | 4 | 4 |
float | 4 | 4 |
double | 8 | 8 |
short | 2 | 2 |
long | 4 | 8 |
long long | 8 | 8 |
void* | 4 | 8 |
类型 | 32位编译器 | 64位编译器 | 本质 |
---|---|---|---|
int8/uint8 | 1 | 1 | signed char/unsigned char |
int16/uint16 | 2 | 2 | signed short/unsigned short |
int32/uint32 | 4 | 4 | signed int/unsigned int |
int64/uint64 | 8 | 8 | signed long long int/unsigned long long int |
byte | 1 | 1 | uint8/unsigned char |
rune | 4 | 4 | int32/signed int |
int | 4 | 8 | 根据机器位数决定长度 |
uintptr | 4 | 8 | 根据机器位数决定长度 uint32/uint64 |
float32 | 4 | 4 | float |
float64 | 8 | 8 | double |
true | 1 | 1 | char类型的整型 |
false | 1 | 1 | char类型的整型 |
解压后打开路径: go\src\runtime\runtime.h
// 第8行到35行
typedef signed char int8;
typedef unsigned char uint8;
typedef signed short int16;
typedef unsigned short uint16;
typedef signed int int32;
typedef unsigned int uint32;
typedef signed long long int int64;
typedef unsigned long long int uint64;
typedef float float32;
typedef double float64;
#ifdef _64BIT
typedef uint64 uintptr;
typedef int64 intptr;
typedef int64 intgo; // Go's int
typedef uint64 uintgo; // Go's uint
#else
typedef uint32 uintptr;
typedef int32 intptr;
typedef int32 intgo; // Go's int
typedef uint32 uintgo; // Go's uint
#endif
#ifdef _64BITREG
typedef uint64 uintreg;
#else
typedef uint32 uintreg;
#endif
// 第153行到157行
enum
{
true = 1,
false = 0,
};
install B 时刻:
Go本质就是用C语言编写的一门高级编程语言
所以江哥前面教你C语言就是为了今天能让你看懂Go的实现代码,做到知其然知其所以然
数据类型 变量名称 = 值;
const 数据类型 常量名称 = 值;
var 变量名称 数据类型 = 值;
const 变量名称 数据类型 = 值;
// 被注释内容
/* 被注释内容*/