pascal语言翻译成c,c++语言!!!!!!!!

qdlgx 2008-09-25 07:57:53
(pascal)
var
vcodes:array of record
id:integer;
data:tbitarray; (注释tbitarray:array of byte;)

newid:integer;

tag:byte;
jumppos:tlongarray;(注释tlongarray:array of integer;)

end;

procedure clearvcode;
var vc:integer;
begin
for vc:=0 to high(vcodes) do begin
setlength(vcodes[vc].data,0);
setlength(vcodes[vc].jumppos,0);
end;
setlength(vcodes,0);

end;
对应的C是什么???




...全文
166 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
太乙 2008-09-27
  • 打赏
  • 举报
回复


if (pUserData == NULL)
return;


太乙 2008-09-27
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 qdlgx 的回复:]
请问free的时间不需要判断vcodes[vc].data,vcodes[vc].jumppos是否为空吗?
[/Quote]

可以判断一下,也可以不用判断!当然,不判断的前提是指针为NULL

以下是free原码:


_CRTIMP void __cdecl free(
void * pUserData
)
{
_free_dbg(pUserData, _NORMAL_BLOCK);
}





#ifdef _MT

_CRTIMP void __cdecl _free_dbg(
void * pUserData,
int nBlockUse
)
{
/* lock the heap
*/
_mlock(_HEAP_LOCK);

__try {
/* allocate the block
*/
_free_dbg_lk(pUserData, nBlockUse);
}
__finally {
/* unlock the heap
*/
_munlock(_HEAP_LOCK);
}
}

void __cdecl _free_dbg_lk(

#else /* _MT */

_CRTIMP void __cdecl _free_dbg(

#endif /* _MT */

void * pUserData,
int nBlockUse
)
{
_CrtMemBlockHeader * pHead;

/* verify heap before freeing */
if (_crtDbgFlag & _CRTDBG_CHECK_ALWAYS_DF)
_ASSERTE(_CrtCheckMemory());

if (pUserData == NULL)
return;

/* forced failure */
if (!(*_pfnAllocHook)(_HOOK_FREE, pUserData, 0, nBlockUse, 0L, NULL, 0))
{
_RPT0(_CRT_WARN, "Client hook free failure.\n");

return;
}

/*
* If this ASSERT fails, a bad pointer has been passed in. It may be
* totally bogus, or it may have been allocated from another heap.
* The pointer MUST come from the 'local' heap.
*/
_ASSERTE(_CrtIsValidHeapPointer(pUserData));

/* get a pointer to memory block header */
pHead = pHdr(pUserData);

/* verify block type */
_ASSERTE(_BLOCK_TYPE_IS_VALID(pHead->nBlockUse));

/* if we didn't already check entire heap, at least check this object */
if (!(_crtDbgFlag & _CRTDBG_CHECK_ALWAYS_DF))
{
/* check no-mans-land gaps */
if (!CheckBytes(pHead->gap, _bNoMansLandFill, nNoMansLandSize))
_RPT3(_CRT_ERROR, "DAMAGE: before %hs block (#%d) at 0x%08X.\n",
szBlockUseName[_BLOCK_TYPE(pHead->nBlockUse)],
pHead->lRequest,
(BYTE *) pbData(pHead));

if (!CheckBytes(pbData(pHead) + pHead->nDataSize, _bNoMansLandFill, nNoMansLandSize))
_RPT3(_CRT_ERROR, "DAMAGE: after %hs block (#%d) at 0x%08X.\n",
szBlockUseName[_BLOCK_TYPE(pHead->nBlockUse)],
pHead->lRequest,
(BYTE *) pbData(pHead));
}

if (pHead->nBlockUse == _IGNORE_BLOCK)
{
_ASSERTE(pHead->nLine == IGNORE_LINE && pHead->lRequest == IGNORE_REQ);
/* fill the entire block including header with dead-land-fill */
memset(pHead, _bDeadLandFill,
sizeof(_CrtMemBlockHeader) + pHead->nDataSize + nNoMansLandSize);
_free_base(pHead);
return;
}

/* CRT blocks can be freed as NORMAL blocks */
if (pHead->nBlockUse == _CRT_BLOCK && nBlockUse == _NORMAL_BLOCK)
nBlockUse = _CRT_BLOCK;

/* Error if freeing incorrect memory type */
_ASSERTE(pHead->nBlockUse == nBlockUse);

/* keep track of total amount of memory allocated */
_lCurAlloc -= pHead->nDataSize;

/* optionally reclaim memory */
if (!(_crtDbgFlag & _CRTDBG_DELAY_FREE_MEM_DF))
{
/* remove from the linked list */
if (pHead->pBlockHeaderNext)
{
pHead->pBlockHeaderNext->pBlockHeaderPrev = pHead->pBlockHeaderPrev;
}
else
{
_ASSERTE(_pLastBlock == pHead);
_pLastBlock = pHead->pBlockHeaderPrev;
}

if (pHead->pBlockHeaderPrev)
{
pHead->pBlockHeaderPrev->pBlockHeaderNext = pHead->pBlockHeaderNext;
}
else
{
_ASSERTE(_pFirstBlock == pHead);
_pFirstBlock = pHead->pBlockHeaderNext;
}

/* fill the entire block including header with dead-land-fill */
memset(pHead, _bDeadLandFill,
sizeof(_CrtMemBlockHeader) + pHead->nDataSize + nNoMansLandSize);
_free_base(pHead);
}
else
{
pHead->nBlockUse = _FREE_BLOCK;

/* keep memory around as dead space */
memset(pbData(pHead), _bDeadLandFill, pHead->nDataSize);
}
}




qdlgx 2008-09-26
  • 打赏
  • 举报
回复
请问free的时间不需要判断vcodes[vc].data,vcodes[vc].jumppos是否为空吗?
太乙 2008-09-26
  • 打赏
  • 举报
回复


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


typedef struct {
int id;
unsigned char* data;
int newid;
unsigned char tag;
int* jumppos;
}Vcode;
Vcode* vcodes;
void main()
{
int vc;
vcodes = (Vcode*)malloc(sizeof(Vcode)*12);
for(vc=0;vc<12;vc++)
{
vcodes[vc].id=vc;
vcodes[vc].data=(unsigned char*)malloc(sizeof(unsigned char)*4);
vcodes[vc].newid=vc+1;
vcodes[vc].tag='a';
vcodes[vc].jumppos=(int*)malloc(sizeof(int)*2);
}
for(vc=0;vc<12;vc++)
{
free(vcodes[vc].data);
free(vcodes[vc].jumppos);
}
free(vcodes);
}

//记住,free的东西,一定要保证前面有malloc!




太乙 2008-09-26
  • 打赏
  • 举报
回复


var
vcodes:array of record
id:integer;
data:tbitarray; (注释tbitarray:array of byte;)

newid:integer;

tag:byte;
jumppos:tlongarray;(注释tlongarray:array of integer;)

end;

procedure clearvcode;
var vc:integer;
begin
for vc:=0 to high(vcodes) do begin
setlength(vcodes[vc].data,0);
setlength(vcodes[vc].jumppos,0);
end;
setlength(vcodes,0);

end;







typedef struct {
int id;
unsigned char* data;
int newid;
unsigned char tag;
int* jumppos;
}Vcode;
Vcode* vcodes;

procedure clearvcode; //不清楚
int vc;
for(vc=0;vc<vcodes的大小;vc++)//vcodes的 大小在于你的分配,比如malloc(sizeof(Vcode)*num)那么就是vc<num
{
free(vcodes[vc].data);
free(vcodes[vc].jumppos);
}
free(vcodes)





chenzhp 2008-09-26
  • 打赏
  • 举报
回复
看看这篇帖子,或许有用

http://bbs.pfan.cn/post-166685.html
e_sharp 2008-09-26
  • 打赏
  • 举报
回复
typedef struct {
int id;
char* data;
int newid;
char tag;
int* jumppos;
}Data;

Data* vcodes; //array of record
int nLength; //动态分配的数组大小,malloc分配内存时分配的大小

void clearvcode() {
int vc;
for(vc = 0; vc < nLength; vc++) {
free(vcodes[vc].data);
free(vcodes[vc].jumppos);
}

free(vcodes);
}
qdlgx 2008-09-26
  • 打赏
  • 举报
回复
up1
ysuliu 2008-09-25
  • 打赏
  • 举报
回复
好像有人问过类似的pascal转C的问题。。。

不会,帮顶~

64,660

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧