Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > how to get binary representation of c objects ?

Reply
Thread Tools

how to get binary representation of c objects ?

 
 
Richard Heathfield
Guest
Posts: n/a
 
      01-16-2008
CBFalconer said:

> jacob navia wrote:
>>

> ... snip ...
>>
>> lcc-win implements %b
>> #include <stdio.h>
>> int main(void) {
>> printf("%b\n",12345);
>> }
>>
>> Output:
>> 11000000111001

>
> A failure. It should output the string "b", followed by a newline,
> and should ignore the "12345". See the C standard for this correct
> performance.


Wrong. "If a conversion specification is invalid, the behavior is
undefined." - C89, 4.9.6.1; C99, 7.19.6.1(9) - same wording in each.
Therefore, neither the de jure nor the de facto C standard imposes any
requirements whatsoever on a program containing a %b format specifier in a
call to any of the *printf standard library functions, and they certainly
do not impose the behaviour you specify.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
 
Reply With Quote
 
 
 
 
Kelsey Bjarnason
Guest
Posts: n/a
 
      01-16-2008
On Wed, 16 Jan 2008 08:44:03 +0000, Mark Bluemel wrote:

> jacob navia wrote:
>
>> I am bad bad bad...
>>
>>
>>
>> Satisfied?

>
> Nope. The beatings will continue until morale improves...


You say that as if it's ironic or something.
 
Reply With Quote
 
 
 
 
Kelsey Bjarnason
Guest
Posts: n/a
 
      01-16-2008
[snips]

On Wed, 16 Jan 2008 05:39:03 +0100, jacob navia wrote:

>> Of course, that sort of thing would be fine if you're writing, oh, a BASIC
>> implementation, but you seem to be flogging it here as a _C_
>> implementation, which it ain't. As the above demonstrates.

>
> I am bad bad bad...
>
>
>
> Satisfied?


Not really. Then again, I don't really expect you to stop flogging the
thing here; you have a financial incentive to do so, whether it's
fundamentally broken, partially broken, absolutely perfect or otherwise.
 
Reply With Quote
 
Philip Potter
Guest
Posts: n/a
 
      01-16-2008
CBFalconer wrote:
> jacob navia wrote:
> ... snip ...
>> lcc-win implements %b
>> #include <stdio.h>
>> int main(void) {
>> printf("%b\n",12345);
>> }
>>
>> Output:
>> 11000000111001

>
> A failure. It should output the string "b", followed by a newline,
> and should ignore the "12345". See the C standard for this correct
> performance. This does not allow this extension.


My C draft states that this is UB. n1256 7.19.6p9. If you're going to
cite the C Standard, you should check it first!

I don't see anything which prevents implementations from providing this
extension - it just warns implementors that their extension may clash
with future versions of the C Standard, at which point the extension
becomes invalid.

I suppose that you could interpret 7.26.9 as reserving "%b" in the same
way that the other subsections within 7.26 reserve the strxxx, toxxx,
isxxx and EXXX identifiers, but it doesn't explicitly say this.

[Having said that, it would be bad practise for an implementation to use
%b rather than %B, even if it is (possibly) allowed.]

Phil
 
Reply With Quote
 
Richard Bos
Guest
Posts: n/a
 
      01-16-2008
Kelsey Bjarnason <(E-Mail Removed)> wrote:

> On Tue, 15 Jan 2008 10:16:14 +0100, jacob navia wrote:
>
> > Using the standard when adding extensions? They are, for
> > obvious reasons, not in the standard. What I did not know was that
> > the standard reserved letters for extensions.

>
> I think that's the point: the standard says "x is reserved" so you merrily
> go and use it anyways, which is directly contradictory to the requirements
> imposed by the standard... so if you're not using the standard to develop
> your implementation, what *are* you using? Tea leaves?


Psychorectal extraction.

> Of course, that sort of thing would be fine if you're writing, oh, a BASIC
> implementation,


It wouldn't, actually. There is an ISO Standard for BASIC, as well.

Richard
 
Reply With Quote
 
Philip Potter
Guest
Posts: n/a
 
      01-16-2008
Philip Potter wrote:
> My C draft states that this is UB. n1256 7.19.6p9. If you're going to
> cite the C Standard, you should check it first!

Sorry, 7.19.6.1p9.

 
Reply With Quote
 
CBFalconer
Guest
Posts: n/a
 
      01-16-2008
Richard Heathfield wrote:
> CBFalconer said:
>> jacob navia wrote:
>>>

>> ... snip ...
>>>
>>> lcc-win implements %b
>>> #include <stdio.h>
>>> int main(void) {
>>> printf("%b\n",12345);
>>> }
>>>
>>> Output:
>>> 11000000111001

>>
>> A failure. It should output the string "b", followed by a newline,
>> and should ignore the "12345". See the C standard for this correct
>> performance.

>
> Wrong. "If a conversion specification is invalid, the behavior is
> undefined." - C89, 4.9.6.1; C99, 7.19.6.1(9) - same wording in each.
> Therefore, neither the de jure nor the de facto C standard imposes
> any requirements whatsoever on a program containing a %b format
> specifier in a call to any of the *printf standard library functions,
> and they certainly do not impose the behaviour you specify.


Oh well. At least I supplied the world an accurate pbin() routine
(which you snipped) which will avoid the need for any such
misconstruing of the standard in the future. In fact it can
be called from the printf code when so signalled by a future %B
specification.


--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.



--
Posted via a free Usenet account from http://www.teranews.com

 
Reply With Quote
 
Ben Bacarisse
Guest
Posts: n/a
 
      01-16-2008
CBFalconer <(E-Mail Removed)> writes:

> Richard Heathfield wrote:
>> CBFalconer said:
>>> jacob navia wrote:
>>>>
>>> ... snip ...
>>>>
>>>> lcc-win implements %b
>>>> #include <stdio.h>
>>>> int main(void) {
>>>> printf("%b\n",12345);
>>>> }
>>>>
>>>> Output:
>>>> 11000000111001
>>>
>>> A failure. It should output the string "b", followed by a newline,
>>> and should ignore the "12345". See the C standard for this correct
>>> performance.

>>
>> Wrong. "If a conversion specification is invalid, the behavior is
>> undefined." - C89, 4.9.6.1; C99, 7.19.6.1(9) - same wording in each.
>> Therefore, neither the de jure nor the de facto C standard imposes
>> any requirements whatsoever on a program containing a %b format
>> specifier in a call to any of the *printf standard library functions,
>> and they certainly do not impose the behaviour you specify.

>
> Oh well. At least I supplied the world an accurate pbin() routine
> (which you snipped) which will avoid the need for any such
> misconstruing of the standard in the future. In fact it can
> be called from the printf code when so signalled by a future %B
> specification.


I doubt it! You routine does not have any way to control the output
width or padding and it prints a leading 0 for every number. It is
not a natural choice for a printf implementer.

--
Ben.
 
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
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Binary data representation Charles T. C++ 11 02-05-2004 04:06 PM
Re: Converting integer to binary representation Mark Dufour Python 5 12-18-2003 05:28 AM
Re: Converting integer to binary representation Harry George Python 1 12-16-2003 02:48 PM
Converting integer to binary representation Mark Dufour Python 0 12-16-2003 02:26 PM



Advertisments