In software engineering, clobbering a file or computer memory is overwriting its contents. The Jargon File defines clobbering as "overwrit[ing], usually unintentionally: 'I walked off the end of the array and clobbered the stack.' Compare mung, scribble, trash, and smash the stack."[1]
Often this happens unintentionally, e.g., using the > redirection operator. To prevent unintentional clobbering, various means are used. For example, the setting shell parameter set -o noclobber (bash, ksh) or set noclobber (csh, tcsh) will prevent > from clobbering by making it issue an error message instead:[2]
$ echo "Hello, world" >file.txt
$ echo "This will overwrite the first greeting." >file.txt
$ set -o noclobber
$ echo "Can we overwrite it again?" >file.txt
-bash: file.txt: cannot overwrite existing file
$ echo "But we can use the >| operator to ignore the noclobber." >|file.txt
$ # Successfully overwrote the contents of file.txt using the >| operator
$ set +o noclobber # Changes setting back
In makefiles, a common target clobber means complete cleanup of all unnecessary files and directories produced by previous invocations of the make command.[3] It is a more severe target than clean and is commonly used to uninstall software. Some make-related commands invoke "make clobber" during their execution. They check the CLOBBER environment variable. If it is set to OFF then clobbering is not done.[4]
In assembler programming, the term 'clobbered registers' is used to denote any registers whose value may be overwritten during the course of executing an instruction.
本文介绍了在软件工程中,文件或计算机内存被覆盖的概念及其预防措施。通常这种情况是由于无意的操作导致,例如使用重定向操作符时未注意到目标文件已存在。文章还探讨了在makefiles中如何使用clobber目标来清理不必要的文件。
113

被折叠的 条评论
为什么被折叠?



