Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > help,why does dev-c++ generate the warnings

Reply
Thread Tools

help,why does dev-c++ generate the warnings

 
 
gaulle
Guest
Posts: n/a
 
      08-10-2004
i'm a newbie in c. now i 'm learning it.i read a code,and compile it in
dev-c++4.9.9.0.it can
be compiled and pass.but there are some warnings.while in TC2.0,no any
warning.it's why?

#include <stdio.h>
#include <time.h>
#include <stdlib.h>

void shuffle(int[][13]);
void deal(const int[][13],const char *[],const char *[]);

main()
{
char * suit[4]={"hearts","diamonds","clubs","spades"};
char * face[13]={"ace","deuce","three","four","five","six","seven "
,"eight","nine","ten","jack","queen","king"};
int deck[4][13]={0};

srand(time(NULL));

shuffle(deck);
deal(deck,face,suit);

getch();
return 0;
}

void shuffle(int wdeck[][13])
{
int card ,row,column;
for(card=1;card<=52;card++)
{
row=rand()%4;
column=rand()%13;

while(wdeck[row][column]!=0)
{
row=rand()%4;
column=rand()%13;
}
wdeck[row][column]=card;
}
}

void deal(const int wdeck[][13],
const char *wface[],
const char *wsuit[])
{
int card,row,column;

for(card=1;card<=52;card++)
for(row=0;row<=3;row++)
for(column=0;column<=12;column++)

if(wdeck[row][column]==card)
printf("%5s of
%8s%c",wface[column],wsuit[row],card%2==0?'\n':'\t');
}
 
Reply With Quote
 
 
 
 
Ed Morton
Guest
Posts: n/a
 
      08-10-2004


gaulle wrote:

> i'm a newbie in c. now i 'm learning it.i read a code,and compile it in
> dev-c++4.9.9.0.it can
> be compiled and pass.but there are some warnings.while in TC2.0,no any
> warning.it's why?


If you want to know why you're getting specific warnings, why, oh why
would you not post those specific warnings?

Ed.

 
Reply With Quote
 
 
 
 
Martin Ambuhl
Guest
Posts: n/a
 
      08-10-2004
gaulle wrote:
> i'm a newbie in c. now i 'm learning it.i read a code,and compile it in
> dev-c++4.9.9.0.it can
> be compiled and pass.but there are some warnings.while in TC2.0,no any
> warning.it's why?


The unmodified OP's code is at EOM. Here is an edited version with the
syntactical problems (and some stylistic ones) fixed & commented on:

#include <stdio.h>
#include <time.h>
#include <stdlib.h>

void shuffle(int[][13]);

/* mha: for the 'const' deleted from the line below, see the
comments between the calls to shuffle and deal. */
void deal(int[][13], const char *[], const char *[]);

/* mha: main returns an int. It does so implicitly under the old
standard, but implicit int is no longer part of the language. I have
changed 'main()' to the line below. */
int main(void)
{
/* mha: for the 'const' added to the two lines below, see the
comments between the calls to shuffle and deal. */
const char *suit[4] = { "hearts", "diamonds", "clubs", "spades" };
const char *face[13] =
{ "ace", "deuce", "three", "four", "five", "six", "seven",
"eight", "nine", "ten", "jack", "queen", "king"};

/* mha: The initialization 'int deck[4][13]={0};' is ok, but fully
bracketed initializations are better. I have changed it below. */
int deck[4][13] = { {0} };

srand(time(NULL));

shuffle(deck);

/* mha: deal() takes arguments of types const int[][13], const char
*[], and const char *[]. But the supplied argments are none of
them const. Welcome to the world of const poisoning. It is easy
enough to make suit and face arrays of pointers to const char (see
declarations above), but deck cannot be made into an array of
arrays of const int, since shuffle modifies it. This means we need
to change the type of the 1st parameter that deal expects. */
deal(deck, face, suit);

/* mha: the line below referred to a non-standard function 'getch()'.
I have changed it to a standard function. */
getchar();
return 0;
}

void shuffle(int wdeck[][13])
{
/* mha: I have not touched the four statements calling rand() in this
function. The FAQ has much better was of using rand() to get a
value in a range [0,N]. */

int card, row, column;
for (card = 1; card <= 52; card++) {
row = rand() % 4;
column = rand() % 13;

while (wdeck[row][column] != 0) {
row = rand() % 4;
column = rand() % 13;
}
wdeck[row][column] = card;
}
}

/* mha: for the 'const' deleted from the line below, see the
comments between the calls to shuffle and deal. */
void deal(int wdeck[][13], const char *wface[], const char *wsuit[])
{
int card, row, column;

for (card = 1; card <= 52; card++)
for (row = 0; row <= 3; row++)
for (column = 0; column <= 12; column++)

if (wdeck[row][column] == card)

/* mha: The line below had a string literal broken
internally by a line break. I have fixed it. */
printf("%5s of%8s%c", wface[column], wsuit[row],
card % 2 == 0 ? '\n' : '\t');
}






[OP's Code]
>
> #include <stdio.h>
> #include <time.h>
> #include <stdlib.h>
>
> void shuffle(int[][13]);
> void deal(const int[][13],const char *[],const char *[]);
>
> main()
> {
> char * suit[4]={"hearts","diamonds","clubs","spades"};
> char * face[13]={"ace","deuce","three","four","five","six","seven "
> ,"eight","nine","ten","jack","queen","king"};
> int deck[4][13]={0};
>
> srand(time(NULL));
>
> shuffle(deck);
> deal(deck,face,suit);
>
> getch();
> return 0;
> }
>
> void shuffle(int wdeck[][13])
> {
> int card ,row,column;
> for(card=1;card<=52;card++)
> {
> row=rand()%4;
> column=rand()%13;
>
> while(wdeck[row][column]!=0)
> {
> row=rand()%4;
> column=rand()%13;
> }
> wdeck[row][column]=card;
> }
> }
>
> void deal(const int wdeck[][13],
> const char *wface[],
> const char *wsuit[])
> {
> int card,row,column;
>
> for(card=1;card<=52;card++)
> for(row=0;row<=3;row++)
> for(column=0;column<=12;column++)
>
> if(wdeck[row][column]==card)
> printf("%5s of
> %8s%c",wface[column],wsuit[row],card%2==0?'\n':'\t');
> }

 
Reply With Quote
 
gaulle
Guest
Posts: n/a
 
      08-10-2004
thanks,it work well.
在 Tue, 10 Aug 2004 01:20:33 -0400,Martin Ambuhl <>
写道:

> gaulle wrote:
>> i'm a newbie in c. now i 'm learning it.i read a code,and compile it
>> in dev-c++4.9.9.0.it can
>> be compiled and pass.but there are some warnings.while in TC2.0,no any
>> warning.it's why?

>
> The unmodified OP's code is at EOM. Here is an edited version with the
> syntactical problems (and some stylistic ones) fixed & commented on:
>
> #include <stdio.h>
> #include <time.h>
> #include <stdlib.h>
>
> void shuffle(int[][13]);
>
> /* mha: for the 'const' deleted from the line below, see the
> comments between the calls to shuffle and deal. */
> void deal(int[][13], const char *[], const char *[]);
>
> /* mha: main returns an int. It does so implicitly under the old
> standard, but implicit int is no longer part of the language. I have
> changed 'main()' to the line below. */
> int main(void)
> {
> /* mha: for the 'const' added to the two lines below, see the
> comments between the calls to shuffle and deal. */
> const char *suit[4] = { "hearts", "diamonds", "clubs", "spades" };
> const char *face[13] =
> { "ace", "deuce", "three", "four", "five", "six", "seven",
> "eight", "nine", "ten", "jack", "queen", "king"};
>
> /* mha: The initialization 'int deck[4][13]={0};' is ok, but fully
> bracketed initializations are better. I have changed it below. */
> int deck[4][13] = { {0} };
>
> srand(time(NULL));
>
> shuffle(deck);
>
> /* mha: deal() takes arguments of types const int[][13], const char
> *[], and const char *[]. But the supplied argments are none of
> them const. Welcome to the world of const poisoning. It is easy
> enough to make suit and face arrays of pointers to const char (see
> declarations above), but deck cannot be made into an array of
> arrays of const int, since shuffle modifies it. This means we need
> to change the type of the 1st parameter that deal expects. */
> deal(deck, face, suit);
>
> /* mha: the line below referred to a non-standard function 'getch()'.
> I have changed it to a standard function. */
> getchar();
> return 0;
> }
>
> void shuffle(int wdeck[][13])
> {
> /* mha: I have not touched the four statements calling rand() in this
> function. The FAQ has much better was of using rand() to get a
> value in a range [0,N]. */
>
> int card, row, column;
> for (card = 1; card <= 52; card++) {
> row = rand() % 4;
> column = rand() % 13;
>
> while (wdeck[row][column] != 0) {
> row = rand() % 4;
> column = rand() % 13;
> }
> wdeck[row][column] = card;
> }
> }
>
> /* mha: for the 'const' deleted from the line below, see the
> comments between the calls to shuffle and deal. */
> void deal(int wdeck[][13], const char *wface[], const char *wsuit[])
> {
> int card, row, column;
>
> for (card = 1; card <= 52; card++)
> for (row = 0; row <= 3; row++)
> for (column = 0; column <= 12; column++)
>
> if (wdeck[row][column] == card)
>
> /* mha: The line below had a string literal broken
> internally by a line break. I have fixed it. */
> printf("%5s of%8s%c", wface[column], wsuit[row],
> card % 2 == 0 ? '\n' : '\t');
> }
>
>
>
>
>
>
> [OP's Code]
>> #include <stdio.h>
>> #include <time.h>
>> #include <stdlib.h>
>> void shuffle(int[][13]);
>> void deal(const int[][13],const char *[],const char *[]);
>> main()
>> {
>> char * suit[4]={"hearts","diamonds","clubs","spades"};
>> char * face[13]={"ace","deuce","three","four","five","six","seven "
>> ,"eight","nine","ten","jack","queen","king"};
>> int deck[4][13]={0};
>> srand(time(NULL));
>> shuffle(deck);
>> deal(deck,face,suit);
>> getch();
>> return 0;
>> }
>> void shuffle(int wdeck[][13])
>> {
>> int card ,row,column;
>> for(card=1;card<=52;card++)
>> {
>> row=rand()%4;
>> column=rand()%13;
>> while(wdeck[row][column]!=0)
>> {
>> row=rand()%4;
>> column=rand()%13;
>> }
>> wdeck[row][column]=card;
>> }
>> }
>> void deal(const int wdeck[][13],
>> const char *wface[],
>> const char *wsuit[])
>> {
>> int card,row,column;
>> for(card=1;card<=52;card++)
>> for(row=0;row<=3;row++)
>> for(column=0;column<=12;column++)
>> if(wdeck[row][column]==card)
>> printf("%5s of
>> %8s%c",wface[column],wsuit[row],card%2==0?'\n':'\t');
>> }




--
使用 Opera 革命性的电子邮件客户程序 M2: http://www.opera.com/m2/
 
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
how can i generate warnings for implicit casts that lose bits? robert bristow-johnson C Programming 13 07-11-2007 10:03 PM
how can i generate warnings for implicit casts that lose bits? robert bristow-johnson C Programming 76 07-02-2007 08:03 AM
How to generate warnings when How generate a warning when int is converted to bool or vice versa? PengYu.UT@gmail.com C++ 3 04-06-2006 11:24 PM
How to generate variable labels for same component within a generate loop Weng Tianxiang VHDL 5 02-16-2006 01:45 PM
use warnings; and use Warnings; give different results Ted Sung Perl Misc 1 08-30-2004 10:22 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57