Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Converting unsigned long to string in C

Reply
Thread Tools

Converting unsigned long to string in C

 
 
Richard Heathfield
Guest
Posts: n/a
 
      02-25-2008
Serve Laurijssen said:

>
> "Richard Heathfield" <(E-Mail Removed)> schreef in bericht
> news:(E-Mail Removed)...


<snip>

>> char s[(CHAR_BIT * sizeof n + 2) / 3 + 1];

>
>
> I would do two things different. First its not immediately obvious where
> the buffer size calculation comes from so I'd put that in a macro.
> Second, if n becomes signed in the future you need one more space if n
> becomes negative. The code gets a little easier to maintain then


The second point is trivially true (but it's still a point worth making).
The first point is more a matter of opinion but, as a matter of fact, I
agree with you.

--
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
 
 
 
 
Richard Tobin
Guest
Posts: n/a
 
      02-25-2008
In article <tunwj.1754$(E-Mail Removed)2.easynews.com>,
Mark McIntyre <(E-Mail Removed)> wrote:

>>>>> I disagree. Since sizeof really is an operator,


>>>> What exactly do you mean by this? In what sense is it "really an
>>>> operator"? It's a unique thing, with its own special syntax.
>>>> It doesn't work like either an operator or a function.


>>> The sense in which it "really is an operator" is the
>>> sense in which the Standard uses the term "operator."


>> Which is not relevant to whether it's more or less confusing to write
>> it without parentheses.


>So what?
>Your question above was "in what sense is it really an operator?". The
>answer is that it is defined as such.


Look up "context" in a dictionary.

-- Richard
--
:wq
 
Reply With Quote
 
 
 
 
Richard Tobin
Guest
Posts: n/a
 
      02-25-2008
In article <(E-Mail Removed)>,
Keith Thompson <(E-Mail Removed)> wrote:

>Note that some languages have a number of operators that use keywords
>(For example, Ada has "and", "or", "xor", "not", "mod", "rem", "abs",
>"not", even though the fundamental arithmetic operators use the usual
>symbols "+", "-", "/", "*".)


I have no objection to operators that are words, but C doesn't have
any apart from sizeof. That makes it look out of place and
distracting in an expression. In a language where such things
were common, it wouldn't.

It is of course just a matter of taste.

-- Richard
--
:wq
 
Reply With Quote
 
Richard Heathfield
Guest
Posts: n/a
 
      02-25-2008
Richard Tobin said:

> In article <(E-Mail Removed)>,
> Keith Thompson <(E-Mail Removed)> wrote:
>
>>Note that some languages have a number of operators that use keywords
>>(For example, Ada has "and", "or", "xor", "not", "mod", "rem", "abs",
>>"not", even though the fundamental arithmetic operators use the usual
>>symbols "+", "-", "/", "*".)

>
> I have no objection to operators that are words, but C doesn't have
> any apart from sizeof.


....except for:

* and
* and_eq
* bitand
* bitor
* compl
* not
* not_eq
* or
* or_eq
* xor
* xor_eq

--
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
 
Richard Tobin
Guest
Posts: n/a
 
      02-25-2008
In article <(E-Mail Removed)>,
Richard Heathfield <(E-Mail Removed)> wrote:

>> I have no objection to operators that are words, but C doesn't have
>> any apart from sizeof.


>...except for:
>
>* and
>[...]


10/10 for pedantry.

-- Richard
--
:wq
 
Reply With Quote
 
Richard Heathfield
Guest
Posts: n/a
 
      02-25-2008
Richard Tobin said:

> In article <(E-Mail Removed)>,
> Richard Heathfield <(E-Mail Removed)> wrote:
>
>>> I have no objection to operators that are words, but C doesn't have
>>> any apart from sizeof.

>
>>...except for:
>>
>>* and
>>[...]

>
> 10/10 for pedantry.


Strictly speaking, it should be 11/11.

--
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
 
Mark McIntyre
Guest
Posts: n/a
 
      02-25-2008
Richard Tobin wrote:
> In article <tunwj.1754$(E-Mail Removed)2.easynews.com>,
> Mark McIntyre <(E-Mail Removed)> wrote:
>

(RT wrote)
>>> Which is not relevant to whether it's more or less confusing to write
>>> it without parentheses.

>
>> Your question above was "in what sense is it really an operator?". The
>> answer is that it is defined as such.

>
> Look up "context" in a dictionary.


Look up "irrelevant". Its an operator in any context. If you don't like
that, raise a DR. If you meant to ask a different question, then say so.

--
Mark McIntyre

CLC FAQ <http://c-faq.com/>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>
 
Reply With Quote
 
Richard
Guest
Posts: n/a
 
      02-25-2008
"J. J. Farrell" <(E-Mail Removed)> writes:

> Richard wrote:
>> Richard Heathfield <(E-Mail Removed)> writes:
>>
>> ...
>>> char s[(CHAR_BIT * sizeof n + 2) / 3 + 1];

>>
>> I hate this "fad" of using "sizeof n". It reads horribly.

>
> What ""fad""? sizeof and its usage has been part of C for a long time.


The fad that I have almost never seen it in production code because
..... it reads horribly. Simple. Practical reasons. The clique here use
it all the time because they are the clique.

 
Reply With Quote
 
Richard
Guest
Posts: n/a
 
      02-25-2008
Mark McIntyre <(E-Mail Removed)> writes:

> Richard Tobin wrote:
>> In article <tunwj.1754$(E-Mail Removed)2.easynews.com>,
>> Mark McIntyre <(E-Mail Removed)> wrote:
>>

> (RT wrote)
>>>> Which is not relevant to whether it's more or less confusing to write
>>>> it without parentheses.

>>
>>> Your question above was "in what sense is it really an
>>> operator?". The answer is that it is defined as such.

>>
>> Look up "context" in a dictionary.

>
> Look up "irrelevant". Its an operator in any context. If you don't
> like that, raise a DR. If you meant to ask a different question, then
> say so.


So you dont think it reads horribly?

it makes no sense to me whatsoever and I dont give a monkeys uncle about
whats in the standard

x = x + sizeof y + 3;

reads like crap in the context of the C programming language.

Operator? Get out of it.

sizeof(y) is obvious to anyone. The above is horrendous. And I dont
believe anyone that says its "as obvious" in the context of other C
code.


 
Reply With Quote
 
Eric Sosman
Guest
Posts: n/a
 
      02-25-2008
Richard wrote:
>
> it makes no sense to me whatsoever and I dont give a monkeys uncle about
> whats in the standard


From the horse's mouth, folks.

--
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
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
(int) -> (unsigned) -> (int) or (unsigned) -> (int) -> (unsigned):I'll loose something? pozz C Programming 12 03-20-2011 11:32 PM
Question on converting unsigned long to std::string Ramesh C++ 2 10-10-2008 07:58 AM
Having compilation error: no match for call to (const __gnu_cxx::hash<long long int>) (const long long int&) veryhotsausage C++ 1 07-04-2008 05:41 PM
unsigned long long int to long double Daniel Rudy C Programming 5 09-20-2005 02:37 AM
Assigning unsigned long to unsigned long long George Marsaglia C Programming 1 07-08-2003 05:16 PM



Advertisments