Memory-reversal Game

  • Thread starter Frederick Gotham
  • Start date
A

Aman JIANG

Richard said:
Aman JIANG said:



I used the following flags:

-W -Wall -ansi -pedantic -Wformat-nonliteral -Wcast-align -Wpointer-arith
-Wbad-function-cast -Wmissing-prototypes -Wstrict-prototypes
-Wmissing-declarations -Winline -Wundef -Wnested-externs -Wcast-qual
-Wshadow -Wconversion -Wwrite-strings -Wno-conversion -ffloat-store -O2


They aren't necessarily bugs. I'm just pointing out that your code isn't
fully portable. That doesn't mean it's *wrong* - it just means I can't
compile it here, using a C90-conforming implementation.

So, how to fix my code that make it could be full-portable, please ?
Or make it could accord with C90 ?
 
R

Richard Heathfield

Aman JIANG said:
So, how to fix my code that make it could be full-portable, please ?
Or make it could accord with C90 ?

To make it C90-conforming, you could start off by using /* comments */
instead of // comments

Also, you could define objects at the beginning of a block, rather than mix
them up with code.

And you could return a value from main.

Consider:

int main(void)
{

Tchar a[] = {'a', 'b', 'c', 'd', 'e'};

Initialize();
ShowBinMemory (a, a + sizeof(a), '\n');
RevMemory (a, a + sizeof(a));
ShowBinMemory (a, a + sizeof(a), '\n');

return 0;
}
 
A

Aman JIANG

Richard said:
Aman JIANG said:
So, how to fix my code that make it could be full-portable, please ?
Or make it could accord with C90 ?

To make it C90-conforming, you could start off by using /* comments */
instead of // comments

Also, you could define objects at the beginning of a block, rather than mix
them up with code.

And you could return a value from main.

Consider:

int main(void)
{

Tchar a[] = {'a', 'b', 'c', 'd', 'e'};

Initialize();
ShowBinMemory (a, a + sizeof(a), '\n');
RevMemory (a, a + sizeof(a));
ShowBinMemory (a, a + sizeof(a), '\n');

return 0;
}


Oh. Thanks for your help. Now I get it.
 
F

Frederick Gotham

Peter Nilsson posted:
Since you mention portability, you should know that you have no
guarantee
that your 'reversed' unsigned ints are not (now) trap representations.


Yes, I realise that. The code in "main" is simply for testing the portable
function.
 
P

Peter Nilsson

Frederick said:
Peter Nilsson posted:
representations.

Yes, I realise that.

Then why post it to comp.lang.c?
The code in "main" is simply for testing the portable function.

What makes you think that you can't do that with portable code?

Portable programming isn't a concept you use solely for theoretical
exercises and 'games', then cast aside when the 'real' programming
begins. ;-)
 
D

Dave Thompson

Aman JIANG said:



So was your previous version.
<OT> He(?) may have used 'last' to mean 'most recent', 'latest'. I
have found this imprecise but I think not definitively wrong usage
common even in native English speakers, which he clearly is not.

<SemiOnTopic> In fact, I have found this so common I consciously avoid
using 'last' in either sense in code. When dealing with linked lists
and other linked/dynamic data structures, I use next and prev, and
head and tail, never last. And usually similarly for files.

<snip substantive comments>

- David.Thompson1 at worldnet.att.net
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top