Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > The machine stack and the C language

Reply
Thread Tools

The machine stack and the C language

 
 
Walter Roberson
Guest
Posts: n/a
 
      01-29-2008
In article <(E-Mail Removed)>,
Keith Thompson <(E-Mail Removed)> wrote:
>But the only reason to
>execute "/bin/true --version" with the expectation of having it do
>nothing is deliberate conformance testing. There's no real-world
>reason to give it an argument at all.


Real life example:

Portable(-ish) Makefiles with a step that would normally be
ar -t (topological sort on the archive contents) but that step
is unneeded or unimplemented on some architectures. The usual
solution is to parameterize the program name as a variable in
the makefile, and for those architectures that do not need or
support the step, use /bin/true or ':' (colon) as the program name,
taking advantage of the fact that arguments will be ignored but
the step will be considered to succeed.

--
'Roberson' is my family name; my given name is 'Walter'.
 
Reply With Quote
 
 
 
 
Keith Thompson
Guest
Posts: n/a
 
      01-29-2008
http://www.velocityreviews.com/forums/(E-Mail Removed)-cnrc.gc.ca (Walter Roberson) writes:
> In article <(E-Mail Removed)>,
> Keith Thompson <(E-Mail Removed)> wrote:
>>But the only reason to
>>execute "/bin/true --version" with the expectation of having it do
>>nothing is deliberate conformance testing. There's no real-world
>>reason to give it an argument at all.

>
> Real life example:
>
> Portable(-ish) Makefiles with a step that would normally be
> ar -t (topological sort on the archive contents) but that step
> is unneeded or unimplemented on some architectures. The usual
> solution is to parameterize the program name as a variable in
> the makefile, and for those architectures that do not need or
> support the step, use /bin/true or ':' (colon) as the program name,
> taking advantage of the fact that arguments will be ignored but
> the step will be considered to succeed.


It's even conceivable that the Makefile might want to invoke
"ar --version", so information about the tools used is recorded in the
output log (if the Makefile assumes that ar accepts the "--version"
option). Invoking "true --version" instead isn't likely to kill
anything, but it could cause some confusion.

If you assume an error "can't happen", stop a moment and consider that
computers are capable of making mistakes that would never occur to a
human, and of making them at an incredible rate. Think about this
before deciding that using an identifier with a leading underscore, or
adding a non-standard declaration to a standard header, or ignoring
the possibility that malloc() could fail, can't possibly cause any
problems in the Real World. The C standard doesn't mention Murphy's
Law, but it still applies.

<EVEN_FURTHER_OT>
More recent versions of the GNU "true" command apparently ignore
POSIXLY_CORRECT.
</EVEN_FURTHER_OT>

--
Keith Thompson (The_Other_Keith) <(E-Mail Removed)>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
 
 
 
Harald van Dijk
Guest
Posts: n/a
 
      01-29-2008
On Tue, 29 Jan 2008 00:24:19 -0800, Keith Thompson wrote:
> Harald van Dijk <(E-Mail Removed)> writes:
>> Fair enough. It's an unnecessary incompatibility with a standard that
>> GNU aims to conform to where it makes sense for them to do so, but as
>> it's an intentional incompatibility, it's not really a bug, it's at
>> worst a design flaw.

>
> But the only reason to execute
> "/bin/true --version" with the expectation of having it do nothing is
> deliberate conformance testing. There's no real-world reason to give it
> an argument at all.


In addition to the example Walter Roberson gave, true and : are sometimes
used as
true ${VAR=value}
to give VAR a value if it's unset. Most shells don't have a built-in
operator to give a variable a default value and then do nothing with it.

Thankfully, most shells implement these utilities as a built-in, which
avoids the problem.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why does std::stack::pop() not throw an exception if the stack is empty? Debajit Adhikary C++ 36 02-10-2011 08:54 PM
Niue - a tiny, embeddable stack language and language toolkit forJava Vijay Mathew Java 0 03-23-2010 11:24 AM
C/C++ compilers have one stack for local variables and return addresses and then another stack for array allocations on the stack. Casey Hawthorne C Programming 3 11-01-2009 08:23 PM
stack frame size on linux/solaris of a running application stack Surinder Singh C Programming 1 12-20-2007 01:16 PM



Advertisments