Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Troubling Alignment (I think) issue.

Reply
Thread Tools

Troubling Alignment (I think) issue.

 
 
Nick Keighley
Guest
Posts: n/a
 
      11-07-2007
On 6 Nov, 20:46, santosh <(E-Mail Removed)> wrote:
> On Wednesday 07 Nov 2007 1:57 am Kevin <(E-Mail Removed)> wrote in
> article <(E-Mail Removed) .com>:


<snip>

> > printf("Locations: %u, %u\r\n", &test, &test1);

>
> No. To print pointers use the '%p' specifier and cast the corresponding
> argument to void *. Also the '\r' is not only not necessary but may
> cause problems. The C Standard library translates a '\n' to whatever
> the system uses as end-of-line.



very rarely explicit \r is needed when the system output doesn't
match the required output. I've even had to generate \r\r\n!
I suppose the output should have been binary rather than text.
I can't rememeber if it was.

<snip>

--
Nick Keighley

 
Reply With Quote
 
 
 
 
santosh
Guest
Posts: n/a
 
      11-07-2007
On Wednesday 07 Nov 2007 2:13 pm Nick Keighley
<(E-Mail Removed)> wrote in article
<(E-Mail Removed). com>:

> On 6 Nov, 20:46, santosh <(E-Mail Removed)> wrote:
>> On Wednesday 07 Nov 2007 1:57 am Kevin <(E-Mail Removed)> wrote
>> in article <(E-Mail Removed) .com>:

>
> <snip>
>
>> > printf("Locations: %u, %u\r\n", &test, &test1);

>>
>> No. To print pointers use the '%p' specifier and cast the
>> corresponding argument to void *. Also the '\r' is not only not
>> necessary but may cause problems. The C Standard library translates a
>> '\n' to whatever the system uses as end-of-line.

>
>
> very rarely explicit \r is needed when the system output doesn't
> match the required output. I've even had to generate \r\r\n!
> I suppose the output should have been binary rather than text.
> I can't rememeber if it was.
>
> <snip>


Is such an implementation non-conforming as per the Standard?

 
Reply With Quote
 
 
 
 
Charlie Gordon
Guest
Posts: n/a
 
      11-08-2007
"santosh" <(E-Mail Removed)> a écrit dans le message de news:
fgqjrb$a8s$(E-Mail Removed)...
> On Wednesday 07 Nov 2007 1:57 am Kevin <(E-Mail Removed)> wrote in
> article <(E-Mail Removed) .com>:
>
>> Hey, I was hoping someone out here might be able to clue me in on some
>> alignment issues I'm having. Hopefully I can explain this best
>> through code below. ACSign and MyACSign functions below get compiled
>> (gcc) into one library, where as the code that executes these
>> functions gets compiled into a seperate library. Calls to MyACSign
>> work fine, calls to the straight ACSign do not and I believe it is due
>> to alignment issues, but I can't pinpoint how. This <i>should</i> have
>> been very elementary. Any help is of course greatly appreciated,
>>
>> - Kevin
>>
>>
>> Function Code:
>> ************************************************** ******************
>> double ACSign ( double a) {
>> if (a > 0.0)
>> return(1.0);

>
> Both the parenthesis and the decimal point are unnecessary.
>
>> else if (a < 0.0)
>> return(-1.0);

>
> Similarly here.
>
>> }


I'm amazed you noticed the extra parentheses and decimal points, and fail to
point at the much more major problem in ACSign: it does not return anything
if a is 0
To properly account for negative zero, it should probably return a.

double ACSign(double a) {
return a < 0 ? -1 : a > 0 ? 1 : a;
}

If we don't care about negative zeroes, ACSign should probably return an int
and can be made even more obscure:

int ACSign(double a) { return (a > 0) - (a < 0); }

Any half decent compiler would have complained about the missing return if
configured properly. Indeed it is a shame that most of them don't complain
for such obvious bugs when invoked without extra flags.

--
Chqrlie.


 
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
Regd---Justify option in Alignment. =?Utf-8?B?bWFudQ==?= ASP .Net 0 09-23-2005 07:35 AM
Phase alignment ALuPin VHDL 0 05-17-2004 09:12 AM
Form2Email troubling my life Benny Alexander ASP General 6 10-29-2003 05:23 AM
Crystal Reports Viewer alignment Anne ASP .Net 0 07-29-2003 03:34 PM
Re: Help required for alignment problem Sunil Menon ASP .Net 0 06-26-2003 07:56 AM



Advertisments