消除静态变量的程序? [英] Procedure for eliminating static variables?

查看:59
本文介绍了消除静态变量的程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这应该很容易,但我不能立即看到答案是什么......


我有一些代码需要重入。它还需要创建

唯一标识符。创建唯一ID的显而易见的方法是

维护一个静态计数器,并在每次需要时增加它。

关于如何执行此操作的任何想法以一种可重入的方式?


我不称这个代码(这是Yacc输出),所以我不能提供任何东西
$ b筹码$ b。


干杯


Ed

解决方案

先生。 Ed写道:

这应该很简单,但我不能立即看到答案是什么......

我有一些代码需要重新进入。它还需要创建一个唯一的标识符。创建唯一ID的显而易见的方法是维护静态计数器,并在每次需要时增加它。
有关如何以可重入方式执行此操作的任何想法?

我不打电话给这个代码(这是Yacc输出),所以我不能在堆栈上提供任何东西。




[..我在clc ++中读到它,所以我回复时没有交叉发布..]


你打算如何使用唯一ID ;?它的ID是什么?哪个每个

时间你是递增的时候了吗?


V


先生。 Ed< ab *** @ [127.0.0.1]>写道:

这应该很简单,但我不能立即看到答案是什么......

我有一些代码需要重入。它还需要创建一个唯一的标识符。创建唯一ID的显而易见的方法是维护静态计数器,并在每次需要时增加它。
有关如何以可重入方式执行此操作的任何想法?




这是OT。


这也是生成唯一ID的坏方法。就像

的食物一样,当程序重启时会发生什么?做独特的ID

回滚到已经使用的值?


Giorgos Keramidas写道:

Mr. Ed< ab *** @ [127.0.0.1]>写道:

这应该很简单,但我不能立即看到答案是什么......

我有一些代码需要重入。它还需要创建一个唯一的标识符。创建唯一ID的显而易见的方法是维护静态计数器,并在每次需要时增加它。
有关如何以可重入方式执行此操作的任何想法?

这是OT。




在哪里?为什么?

[..]



This should be easy, but I can''t immediately see what the answer is...

I have some code which needs to be re-entrant. It also needs to create
a unique identifier. The obvious way to create a unique ID is to
maintain a static counter, and to increment it each time it''s needed.
Any ideas on how to do this in a re-entrant way?

I don''t call this code (it''s Yacc output), so I can''t suppy anything
on the stack.

Cheers

Ed

解决方案

Mr. Ed wrote:

This should be easy, but I can''t immediately see what the answer is...

I have some code which needs to be re-entrant. It also needs to create
a unique identifier. The obvious way to create a unique ID is to
maintain a static counter, and to increment it each time it''s needed.
Any ideas on how to do this in a re-entrant way?

I don''t call this code (it''s Yacc output), so I can''t suppy anything
on the stack.



[.. I read it in c.l.c++, so I am replying without cross-posting ..]

How are you going to use the "unique ID"? What does it ID? Which "each
time" is the time when you increment it?

V


Mr. Ed <ab***@[127.0.0.1]> writes:

This should be easy, but I can''t immediately see what the answer is...

I have some code which needs to be re-entrant. It also needs to create
a unique identifier. The obvious way to create a unique ID is to
maintain a static counter, and to increment it each time it''s needed.
Any ideas on how to do this in a re-entrant way?



This is OT here.

It''s also a bad method for generating unique IDs. Just as food for
thought, what happens when your program restarts? Do the "unique" IDs
roll back to an already used value?


Giorgos Keramidas wrote:

Mr. Ed <ab***@[127.0.0.1]> writes:

This should be easy, but I can''t immediately see what the answer is...

I have some code which needs to be re-entrant. It also needs to create
a unique identifier. The obvious way to create a unique ID is to
maintain a static counter, and to increment it each time it''s needed.
Any ideas on how to do this in a re-entrant way?

This is OT here.



Where? And why?
[..]



这篇关于消除静态变量的程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆