[c-prog] Re: integer promotions

2008-11-23 Thread John Matthews
--- In c-prog@yahoogroups.com, Pedro Izecksohn [EMAIL PROTECTED] wrote: OK, I wrote a bad piece of code. Let me try to codify my problem again: #include limits.h #include stdio.h int main (void) { unsigned short int a; unsigned long long int b, c; a = USHRT_MAX; b = (a*a); c =

[c-prog] Re: integer promotions

2008-11-23 Thread John Matthews
Sorry- must have got up too early: But if you like at these values in hex 'like' - 'look' But hopefully some can quote the relevant bit of the Standard. 'some' - 'someone'

[c-prog] Ahmed Shabana wants to chat

2008-11-23 Thread Ahmed Shabana
--- Ahmed Shabana wants to stay in better touch using some of Google's coolest new products. If you already have Gmail or Google Talk, visit: http://mail.google.com/mail/b-a0c3cfa5cd-0bb9fda036-f3957799f9ad4eee You'll need to

[c-prog] Nested structure segmentation fault ??

2008-11-23 Thread Ahmed Shabana
#includestdio.h #includestring.h struct sub { char name[100]; }; struct maiN { struct sub *s1; int c; }; int main() { struct maiN s0; strcpy(s0.s1-name,hi man ); return 0; } It compile so good but when run get segmentation fault CAN ANY

[c-prog] Re: Nested structure segmentation fault ??

2008-11-23 Thread John Matthews
--- In c-prog@yahoogroups.com, Ahmed Shabana [EMAIL PROTECTED] wrote: struct maiN s0; strcpy(s0.s1-name,hi man ); but when run get segmentation fault You haven't initialised s0, so s1 could be pointing anywhere.

Re: [c-prog] Re: integer promotions

2008-11-23 Thread Tyler Littlefield
hello, If you multiply two unsigned shorts together, you'll get an unsigned short, or, if the number is to big, it'll overflow; you'll want to use an int. Hope that helps somewhat, Thanks, Tyler Littlefield email: [EMAIL PROTECTED] web: tysdomain-com Visit for quality software and web design.

[c-prog] Re: Nested structure segmentation fault ??

2008-11-23 Thread John Matthews
--- In c-prog@yahoogroups.com, David Hamill [EMAIL PROTECTED] wrote: John wrote: You haven't initialised s0, so s1 could be pointing anywhere. But my money would be on it having the value zero. I.e. an uninitialised pointer is a null pointer. I don't know if this is in the standard

[c-prog] Re: Nested structure segmentation fault ??

2008-11-23 Thread John Matthews
--- In c-prog@yahoogroups.com, John Matthews [EMAIL PROTECTED] wrote: So the value of the pointer will be whatever was in memory before, which might be 0, but it very much depends on your compiler/OS/what happened a bit earlier etc. Adding a printf() in the OP's code, using gcc under linux:

Re: [c-prog] Re: Nested structure segmentation fault ??

2008-11-23 Thread Ahmed Shabana
On Sun, Nov 23, 2008 at 1:19 PM, John Matthews [EMAIL PROTECTED] wrote: --- In c-prog@yahoogroups.com, John Matthews [EMAIL PROTECTED] wrote: So the value of the pointer will be whatever was in memory before, which might be 0, but it very much depends on your compiler/OS/what happened a bit

Re: [c-prog] Nested structure segmentation fault ??

2008-11-23 Thread Brett McCoy
On Sun, Nov 23, 2008 at 4:48 AM, Ahmed Shabana [EMAIL PROTECTED] wrote: #includestdio.h #includestring.h struct sub { char name[100]; }; struct maiN { struct sub *s1; int c; }; sub *s1 is a pointer inside maiN int main() { struct maiN s0;

[c-prog] Re: Nested structure segmentation fault ??

2008-11-23 Thread John Matthews
--- In c-prog@yahoogroups.com, Ahmed Shabana [EMAIL PROTECTED] wrote: okay what is the solution of this problem ???/ HOW can I assign the variable which called name Example: int main() { struct sub sub0; struct maiN s0; s0.s1 = sub0; s0.c = 42; strcpy(s0.s1-name,hi

Re: [c-prog] Nested structure segmentation fault ??

2008-11-23 Thread Ahmed Shabana
On Sun, Nov 23, 2008 at 2:10 PM, Brett McCoy [EMAIL PROTECTED] wrote: On Sun, Nov 23, 2008 at 4:48 AM, Ahmed Shabana [EMAIL PROTECTED] wrote: #includestdio.h #includestring.h struct sub { char name[100]; }; struct maiN { struct sub *s1; int c; }; sub *s1 is a pointer inside maiN

[c-prog] Re: Nested structure segmentation fault ??

2008-11-23 Thread John Matthews
Do you need to use a pointer in the maiN structure? If you don't, your program becomes simpler: #include stdio.h #include string.h struct sub { char name[100]; }; struct maiN { struct sub s1; int c; }; int main(void) { struct maiN s0; s0.c = 42; strcpy(s0.s1.name,hi

Re: [c-prog] Re: Nested structure segmentation fault ??

2008-11-23 Thread Paul Herring
On Sun, Nov 23, 2008 at 12:30 PM, John Matthews [EMAIL PROTECTED] wrote: --- In c-prog@yahoogroups.com, John Matthews [EMAIL PROTECTED] wrote: --- In c-prog@yahoogroups.com, Ahmed Shabana UnlimitedEng@ wrote: okay what is the solution of this problem ???/ HOW can I assign the variable

[c-prog] Re: Nested structure segmentation fault ??

2008-11-23 Thread John Matthews
--- In c-prog@yahoogroups.com, John Matthews [EMAIL PROTECTED] wrote: --- In c-prog@yahoogroups.com, Ahmed Shabana UnlimitedEng@ wrote: okay what is the solution of this problem ???/ HOW can I assign the variable which called name Example: int main() { struct sub sub0;

Re: [c-prog] Re: Nested structure segmentation fault ??

2008-11-23 Thread David Hamill
John wrote: You haven't initialised s0, so s1 could be pointing anywhere. But my money would be on it having the value zero. I.e. an uninitialised pointer is a null pointer. I don't know if this is in the standard, but it would be a sensible thing for a compiler to do, as null pointer

Re: [c-prog] Re: Nested structure segmentation fault ??

2008-11-23 Thread Ahmed Shabana
1rst Thanks too much to John Matthews this two solution add to me good background about what is the problem was Or get rid of the problem altogether so you don't have to 'remember' to do anything, and change the containing struct: struct maiN { struct sub s1; /* changed from pointer to the

[c-prog] Re: Nested structure segmentation fault ??

2008-11-23 Thread John Matthews
One other minor point: you can use typedef to save some typing: typedef struct sub { /* remove sub if you want */ : } Sub; typedef struct maiN { /* remove maiN if you want */ : } MaiN; int main(void) { Sub sub0; /* no need for struct */ MaiN s0; /* no need for struct */ John

Re: [c-prog] Re: integer promotions

2008-11-23 Thread Thomas Hruska
John Matthews wrote: --- In c-prog@yahoogroups.com, Pedro Izecksohn [EMAIL PROTECTED] wrote: OK, I wrote a bad piece of code. Let me try to codify my problem again: #include limits.h #include stdio.h int main (void) { unsigned short int a; unsigned long long int b, c; a = USHRT_MAX; b =

[c-prog] Re: integer promotions

2008-11-23 Thread John Matthews
--- In c-prog@yahoogroups.com, Thomas Hruska [EMAIL PROTECTED] wrote: BTW, you should have your compiler warnings turned up so that you get a warning for assigning a signed value to an unsigned variable. Thomas- is this easy in Microsoft world? And anyone know the gcc equivalent? Gcc's -Wall

Re: [c-prog] Re: integer promotions

2008-11-23 Thread Paul Herring
On Sun, Nov 23, 2008 at 2:57 PM, John Matthews [EMAIL PROTECTED] wrote: --- In c-prog@yahoogroups.com, Thomas Hruska [EMAIL PROTECTED] wrote: BTW, you should have your compiler warnings turned up so that you get a warning for assigning a signed value to an unsigned variable. Thomas- is this

[c-prog] Re: integer promotions

2008-11-23 Thread John Matthews
--- In c-prog@yahoogroups.com, Paul Herring [EMAIL PROTECTED] wrote: On Sun, Nov 23, 2008 at 2:57 PM, John Matthews [EMAIL PROTECTED] wrote: --- In c-prog@yahoogroups.com, Thomas Hruska thruska@ wrote: BTW, you should have your compiler warnings turned up so that you get a warning for

[c-prog] Re: integer promotions

2008-11-23 Thread John Matthews
--- In c-prog@yahoogroups.com, Thomas Hruska [EMAIL PROTECTED] wrote: b = (UInt64)(((UInt32)a) * ((UInt32)a)); Would this be even safer: b = (UInt64)a * (UInt64)a; ?

Re: [c-prog] Re: integer promotions

2008-11-23 Thread andrew clarke
On Sun 2008-11-23 14:57:38 UTC-, John Matthews ([EMAIL PROTECTED]) wrote: BTW, you should have your compiler warnings turned up so that you get a warning for assigning a signed value to an unsigned variable. Thomas- is this easy in Microsoft world? And anyone know the gcc equivalent?

Res: [c-prog] Re: integer promotions

2008-11-23 Thread Pedro Izecksohn
--- Thomas Hruska wrote: BTW, you should have your compiler warnings turned up so that you get a warning for assigning a signed value to an unsigned variable. --- John Matthews asked: And anyone know the gcc equivalent? Gcc's -Wall 'all warnings' option doesn't include it. --- andrew

Re: [c-prog] Re: integer promotions

2008-11-23 Thread Thomas Hruska
John Matthews wrote: --- In c-prog@yahoogroups.com, Thomas Hruska [EMAIL PROTECTED] wrote: b = (UInt64)(((UInt32)a) * ((UInt32)a)); Would this be even safer: b = (UInt64)a * (UInt64)a; ? That would do something different. It really depends on what exactly you want to do. I'd still

[c-prog] String and Numbers

2008-11-23 Thread Mirza Abdullah Jan
Hi I have text file in this pattern Jila Tim 45 45 67 5 67 45 3 5 67 89  19823456 Eva Clarare 42 1 8 43 52 76 1 8 90 43 19345678 - - - - - Kim Jomte 4 5 75 24 52 52 35 35 36 35 19745432 I want to get name of each player and total higest score palyer. the last eight digits are not required.

[c-prog] util class for general method

2008-11-23 Thread Jos Timanta Tarigan
Hi, Im curious is it usual to make an util class to contain methods that are going to be used frequently generally? is there any proper format for this class? im planning to make a util.cpp file with some methods, and include the cpp file in every classes. but i wonder since i havent seen an

[c-prog] print number in string

2008-11-23 Thread Tyler Littlefield
Hello list, I'm used to c++ where I can just use a simple stringstream and print the number to the stream. Unfortunately for me, I'm using c now, and need to be able to print a number in a string. Basically, I'm writing a time conversion util; it takes the number of seconds and converts them to

Re: [c-prog] print number in string

2008-11-23 Thread Brett McCoy
On Sun, Nov 23, 2008 at 7:51 PM, Tyler Littlefield [EMAIL PROTECTED] wrote: I'm used to c++ where I can just use a simple stringstream and print the number to the stream. Unfortunately for me, I'm using c now, and need to be able to print a number in a string. Basically, I'm writing a time

Re: [c-prog] print number in string

2008-11-23 Thread Tyler Littlefield
thanks. looks like what I needed, though sprintf might serve a better purpose. Thanks, Tyler Littlefield email: [EMAIL PROTECTED] web: tysdomain-com Visit for quality software and web design. skype: st8amnd2005 - Original Message - From: Brett McCoy To: c-prog@yahoogroups.com

Res: [c-prog] util class for general method

2008-11-23 Thread Pedro Izecksohn
--- Jos Timanta Tarigan wrote: im planning to make a util.cpp file with some methods, and include the cpp file in every classes. but i wonder since i havent seen an included .cpp files(all included are header files) You should not include .cpp files in other .cpp files, but you should

Res: [c-prog] String and Numbers

2008-11-23 Thread Pedro Izecksohn
--- Mirza Abdullah Jan wrote: Hi I have text file in this pattern Jila Tim 45 45 67 5 67 45 3 5 67 89 19823456 Eva Clarare 42 1 8 43 52 76 1 8 90 43 19345678 - - Kim Jomte 4 5 75 24 52 52 35 35 36 35 19745432 I want to get name of each player and total higest score palyer. the

[c-prog] Re: integer promotions

2008-11-23 Thread peternilsson42
Tyler Littlefield [EMAIL PROTECTED] wrote: hello, If you multiply two unsigned shorts together, you'll get an unsigned short, No, you won't. If the range of unsigned short fits into an int, the two unsigned short values will be promoted to int. The multiplication will be performed with ints,

[c-prog] Re: integer promotions

2008-11-23 Thread peternilsson42
Pedro Izecksohn [EMAIL PROTECTED] wrote: If The integer promotions preserve value including sign. There are several 'promotion' rules at play in C (and C++.) For integers with a 'rank' less than int, if the range of the integer type fits into the range of int, then that type will promote to

[c-prog] Re: integer promotions

2008-11-23 Thread Pedro Izecksohn
For peternilsson42: I was not clear and you did not read message 68798. http://tech.groups.yahoo.com/group/c-prog/message/68798 To clarify: That code I compiled on two independent compilers. On both compilers: USHRT_MAX is 0x UINT_MAX is 0x ULLONG_MAX is 0x For

[c-prog] Re: integer promotions

2008-11-23 Thread peternilsson42
Pedro Izecksohn [EMAIL PROTECTED] wrote: For peternilsson42: I was not clear and you did not read message 68798. http://tech.groups.yahoo.com/group/c-prog/message/68798 That post contained detail missing from your original post. However, it did not contain detail which explained why you