包裹思想

扫码查看
感谢您阅读! - 电子邮件是olypen dot com的wtallman 解决方案 "名称" <我们** @ host.domain>写了 好吧,我已经达到了一个里程碑:在这里,我有一个功能齐全的应用程序,如果没有一些初步的东西我就无法使用。如果我要分配动态内存,我需要知道文件长度,或者接受一些类型的猜测程序。还有其他的事情。现在很明显,必须编写一些非便携式代码才能使其有用。 怎么办? 通常情况下你可以使用足够便携。码。如果你想知道一个文件的长度 ,打开它,fseek()到最后,ftell()的位置,并添加一些 百字节为运气。在严格的ANSI术语中,这可能会失败,但实际上很可能是你的代码不可能在病态的 平台上运行。 2004-08-28,Malcolm< ma ***** @ 55bank.freeserve.co.uk>写道:" name" <我们** @ host.domain>写了 好吧,我已经达到了一个里程碑:在这里,我有一个功能齐全的应用程序,如果没有一些初步的东西我就无法使用。如果我要分配动态内存,我需要知道文件长度,或者进行一些 sort 的例程。还有其他的事情。现在很明显,必须编写一些非便携式代码才能使其有用。 怎么办? 通常你可以使用 ;足够便携码。如果你想知道文件的长度,打开它,fseek()到最后,ftell()的位置,并添加一些百字节的运气。在严格的ANSI术语中,这可能会失败,但实际上,您的代码不太可能必须在病态平台上运行。 啊哈。我曾在其他地方聚集过,这实际上并没有奏效,但现在不能确切地记住原因。我确实记得它不被认为是可移植的(我想是......)但是你提出了一个有趣而且看似实用的方法。 有很好的理论依据当然,一般的足够好 方法;问题可能在于确定在任何特定情况下结果是什么。在我看来,真正的问题是技能和程序员的知识。但是它并不总是如此! 通常情况下,我甚至不会提出这个问题,并且可能不会在这里首先发布 。我通常可以通过一些努力获得一些工作,但这不是这个特定项目的意义所在。我想要了解一般的编程方式,从 C程序员的角度来看。所以这些问题就变得相关了。 所以我会接受你的建议并看看我能做些什么。我还要 对足够好 方法的一般意见感兴趣。 感谢您的回复! - 电子邮件是wtlyman at olypen dot com 2004年8月28日星期六,Malcolm写道: " name" <我们** @ host.domain>写了好吧,我已经达到了一个里程碑:这里有一个功能齐全的应用程序,如果没有一些初步的东西,我就无法使用。如果我要分配动态内存,我需要知道文件长度,或者进行一些猜测例程。还有其他的事情。现在很明显,必须编写一些非便携式代码才能使其有用。 怎么办? 通常情况下你可以使用足够便携。码。如果你想知道文件的长度,打开它,fseek()到最后,ftell()的位置,并添加一些百字节的运气。在严格的ANSI术语中,这可能会失败,但实际上,您的代码不太可能必须在病态平台上运行。 确实如此 - 有时你真的需要写非便携式的b $ b或足够便携。码。但是为了避免OP得到错误的想法: 他的程序执行/不执行实现定义的行为。 除非他再次更改了规范,否则需要O (k)内存 k是在命令行输入的数字。这就是 你可以在不知道文件长度的情况下得到的东西。 今晚我会写这个程序,也许会发布一些更多想法 然后。与此同时,我鼓励OP检查''usenetify'', ''usenetify2''和Leor Zolman''''pf'',链接到所有这些都可以;搜索usenetify wrapping, 我想。所有这三个程序都是以便携性写的,并且考虑到了b $ b,他们所做的基本上与OP正在尝试做的事情相同,尽管有更多的铃声和口哨声。 /> -Arthur Well, I''ve reached a milestone: Here I have an adequately functionalapplication I can''t use without some preliminary stuff. If I''m going toassign dynamic memory, I need to know the file length, or undergo some sortof guess routine. And other things as well. It''s now immediately evidentthat some non-portable code must be written to make this useful.What to do?At the moment, I''m inclined to wrap the ''wrap'' code (heh...) in a shellscript which can supply all the parameters handily. Such a script can bewritten for any operating system, of course, and that would leave the codeportable in its own right. Another approach would be to do the same with aGUI routine (I like GTK+), and put all the non-portable code in at that level.The last choice would be to lard the code with system calls to supply theadded functionality, or so I think.I guess the point is to keep the portable code separate and intact. It''seasy to provide all the necessary arguments at command line for the scriptto address, and that way, the app itself could be used manually if therequired information were at hand. Also, any added functionality to thecode itself could be handled the same way, as CL arguments, and the wrapperscript modified accordingly.I guess my question here is: What *do* you guys do about this, and givenoptions, what order of preference thereof is most common?Thanks for reading!--Email is wtallman at olypen dot com 解决方案 "name" <us**@host.domain> wrote Well, I''ve reached a milestone: Here I have an adequately functional application I can''t use without some preliminary stuff. If I''m going to assign dynamic memory, I need to know the file length, or undergo somesort of guess routine. And other things as well. It''s now immediately evident that some non-portable code must be written to make this useful. What to do?Normally you can use "portable enough" code. If you want to know the lengthof a file, open it, fseek() to the end, ftell() the location, and add a fewhundred bytes for luck. In strict ANSI terms this can fail, but practicallyit is unlikely that your code will ever have to run on a pathologicalplatform.On 2004-08-28, Malcolm <ma*****@55bank.freeserve.co.uk> wrote: "name" <us**@host.domain> wrote Well, I''ve reached a milestone: Here I have an adequately functional application I can''t use without some preliminary stuff. If I''m going to assign dynamic memory, I need to know the file length, or undergo some sort of guess routine. And other things as well. It''s now immediately evident that some non-portable code must be written to make this useful. What to do? Normally you can use "portable enough" code. If you want to know the length of a file, open it, fseek() to the end, ftell() the location, and add a few hundred bytes for luck. In strict ANSI terms this can fail, but practically it is unlikely that your code will ever have to run on a pathological platform.Aha. I had gathered elsewhere that this actually didn''t work, but can''t nowremember exactly why. I do recall it wasn''t considered portably (Ithink...), but you raise an interesting and apparently practical approach.There is excellent theoretical justification for the general "good enough"approach, of course; the problem might be in identifying what that turns outto be in any particular case. Seems to me the real issue is the skill andknowledge of the programmer. But is it not always thus!Normally, I wouldn''t even raise this issue, and probably would not haveposted here in the first place. I can generally get something to work witha bit of effort, but that''s not what this particular project is about. Iwant to understand what I can about programming in general, as seen from theC programmer''s point of view. And so these issues thus become relevant.So I''ll take your recommendation and see what I can make of it. I''ll alsobe interested in the general range of opinions regarding the "good enough"approach.Thanks for your response!--Email is wtallman at olypen dot comOn Sat, 28 Aug 2004, Malcolm wrote: "name" <us**@host.domain> wrote Well, I''ve reached a milestone: Here I have an adequately functional application I can''t use without some preliminary stuff. If I''m going to assign dynamic memory, I need to know the file length, or undergo some sort of guess routine. And other things as well. It''s now immediately evident that some non-portable code must be written to make this useful. What to do? Normally you can use "portable enough" code. If you want to know the length of a file, open it, fseek() to the end, ftell() the location, and add a few hundred bytes for luck. In strict ANSI terms this can fail, but practically it is unlikely that your code will ever have to run on a pathological platform.True enough---sometimes you do really need to write non-portableor "portable enough" code. But lest the OP get the wrong idea:His program does /not/ require implementation-defined behavior.Unless he''s changed the specs again, it requires O(k) memory wherek is the number entered at the command line. And that''s somethingyou can get without knowing anything about file lengths.I''ll write the program tonight, and maybe post some more thoughtsthen. In the meantime, I encourage the OP to examine ''usenetify'',''usenetify2'', and Leor Zolman''s ''pf'', links to all of which can befound in the Google Groups archive; search for "usenetify wrapping",I would think. All three programs were written with portabilityin mind, and they all do basically the same thing the OP is tryingto do, albeit with more bells and whistles.-Arthur 这篇关于包裹思想的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
05-27 22:46
查看更多