C++转标准C 注意事项

1.标准C语言不支持类,C++中的类要更改成全局结构体和全局变量。在构造函数中初始化的变量,和析构函数中释放的变量要重新写函数来初始化和释放。

2.C语言不支持new声明存储空间,        

char *Ptr ; 
        Ptr = (char *)malloc(100 * sizeof(char)); 

free(Ptr 

AdjList (*list)[20] = (AdjList(*)[20])malloc(sizeof(AdjList(*)[20])); 

 

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
	int i, row, column, **arr;

	while (scanf("%d %d", &row, &column) != EOF) {
		arr = (int **)malloc(sizeof(int *) * row); // 分配所有行的首地址
		for (i = 0; i < row; i ++) { // 按行分配每一列
			arr[i] = (int *)malloc(sizeof(int) * column);	
		}

		free(arr);
	}

	return 0;
}
#include <stdlib.h>

int main(void)
{
	int i, row, column, **arr;

	while (scanf("%d %d", &row, &column) != EOF) {
		arr = (int **)malloc(sizeof(int *) * row); // 分配所有行的首地址
		for (i = 0; i < row; i ++) { // 按行分配每一列
			arr[i] = (int *)malloc(sizeof(int) * column);	
		}

		free(arr);
	}

	return 0;
}

 

3.C语言不支持cout要用printf   printf("飞行时间:%f\n",z);

4.C语言的文件输入输出流。

#include "stdio.h"

FILE *file;

file = fopen("a.txt","w");

fprintf(file,"xxxxxxxxxx%f\n",a);

4.C语言不支持引用调用,要改为指针调用。

5..h文件要有相应的

#ifndef EXTVAR_H
#define EXTVAR_H

 

#endif 

6.C++调用C,注意调用格式,不然会出现莫名其妙的错误。所有调用的C,都要

声明时

#ifndef EXTVAR_H
#define EXTVAR_H


#ifdef __cplusplus
extern "C" {
#endif

#include "newconst.h"

typedef struct
{
float wx; //角速度
float wy;
float wz;

}IMU_MSG;
//速度位置重置标志位
extern int pos_velo_init;

extern void a();

#ifdef __cplusplus
}
#endif /* extern "C" */
#endif  // end of EXTVAR_H definition


使用相关函数时
extern “C”
{
#include “ s.h”
#include “t.h”
#include “g.h”
#include “j.h”
};
 

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
通过例子介绍使用方法如下: 1.差异统计 统计某一个版本的代码包相对于一个原始的基线代码包,变动的代码量 以及变动的代码量中各语言非空非注释行(NBNC)的结果 diffcount 缺省执行的就是差异统计,直接跟上两个代码包的目录即可 在diffcount目录下执行: diffcount test\sp1 test\sp2 实际使用中,可能会有文件名和目录名大小写不一致的情况,如果希望忽略 文件名大小写的差异,需要使用 --ignore-case 参数,否则两个一样的文件 一个会算作删除,一个会算作新增 G:\diffcount>diffcount test\sp1 test\sp2 Diffcount [test\sp1] and [test\sp2] result: LANG ADD MOD DEL A&M BLK CMT NBNC RATE ----------------------------------------------------------------------- C 44 7 26 51 8 11 35 1.00 Pascal 0 0 25 0 0 0 0 0.23 Java 7 4 11 11 0 3 9 0.41 Config 31 4 0 35 1 0 34 0.12 XML 126 0 0 126 2 0 124 0.12 ----------------------------------------------------------------------- Convert all NBNC lines to standard C Total: 57.65 (standard C lines) ADD MOD DEL A&M BLK CMT NBNC RATE 的 含义分别为: 新增、修改、删除、新增+修改、空行、注释、非空非注释行、标准C折算率 2.代码统计: 如果需要,可以把diffcount当作普通的代码行统计工具,统计一个代码包 代码统计使用 -c (或者--count-only)参数, 在diffcount目录下执行 diffcount -c test\count 执行结果如下: G:\diffcount>diffcount -c test\count Counting package [test\count] result: LANG TOTAL BLK CMT NBNC RATE ----------------------------------------------------------------------- C 203 46 61 101 1.00 C++ 57 7 25 25 0.42 Pascal 117 24 17 79 0.23 Java 71 7 24 40 0.41 ASM 129 34 12 85 2.50 C# 18 1 1 17 0.20 Basic 447 140 20 295 0.21 Perl 97 4 26 74 0.16 TCL/TK 91 12 26 54 0.50 Config 116 13 0 103 0.12 XML 126 2 0 124 0.12 ----------------------------------------------------------------------- Convert

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值