dev-cpp-users Mailing List for Dev-C++ (Page 57)
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
You can subscribe to this list here.
2000 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(15) |
Oct
(115) |
Nov
(154) |
Dec
(258) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2001 |
Jan
(377) |
Feb
(260) |
Mar
(249) |
Apr
(188) |
May
(152) |
Jun
(150) |
Jul
(195) |
Aug
(202) |
Sep
(200) |
Oct
(286) |
Nov
(242) |
Dec
(165) |
2002 |
Jan
(245) |
Feb
(241) |
Mar
(239) |
Apr
(346) |
May
(406) |
Jun
(369) |
Jul
(418) |
Aug
(357) |
Sep
(362) |
Oct
(597) |
Nov
(455) |
Dec
(344) |
2003 |
Jan
(446) |
Feb
(397) |
Mar
(515) |
Apr
(524) |
May
(377) |
Jun
(387) |
Jul
(532) |
Aug
(364) |
Sep
(294) |
Oct
(352) |
Nov
(295) |
Dec
(327) |
2004 |
Jan
(416) |
Feb
(318) |
Mar
(324) |
Apr
(249) |
May
(259) |
Jun
(218) |
Jul
(212) |
Aug
(259) |
Sep
(158) |
Oct
(162) |
Nov
(214) |
Dec
(169) |
2005 |
Jan
(111) |
Feb
(165) |
Mar
(199) |
Apr
(147) |
May
(131) |
Jun
(163) |
Jul
(235) |
Aug
(136) |
Sep
(84) |
Oct
(88) |
Nov
(113) |
Dec
(100) |
2006 |
Jan
(85) |
Feb
(119) |
Mar
(33) |
Apr
(31) |
May
(56) |
Jun
(68) |
Jul
(18) |
Aug
(62) |
Sep
(33) |
Oct
(55) |
Nov
(19) |
Dec
(40) |
2007 |
Jan
(22) |
Feb
(49) |
Mar
(34) |
Apr
(51) |
May
(66) |
Jun
(43) |
Jul
(116) |
Aug
(57) |
Sep
(70) |
Oct
(69) |
Nov
(97) |
Dec
(86) |
2008 |
Jan
(32) |
Feb
(47) |
Mar
(106) |
Apr
(67) |
May
(28) |
Jun
(39) |
Jul
(31) |
Aug
(25) |
Sep
(18) |
Oct
(25) |
Nov
(5) |
Dec
(21) |
2009 |
Jan
(33) |
Feb
(27) |
Mar
(27) |
Apr
(22) |
May
(22) |
Jun
(10) |
Jul
(17) |
Aug
(9) |
Sep
(21) |
Oct
(13) |
Nov
(4) |
Dec
(11) |
2010 |
Jan
(10) |
Feb
(8) |
Mar
(4) |
Apr
(1) |
May
|
Jun
(2) |
Jul
|
Aug
(1) |
Sep
(8) |
Oct
(26) |
Nov
(9) |
Dec
(1) |
2011 |
Jan
(21) |
Feb
(16) |
Mar
(4) |
Apr
(19) |
May
(26) |
Jun
(9) |
Jul
(6) |
Aug
|
Sep
(4) |
Oct
(3) |
Nov
(2) |
Dec
(1) |
2012 |
Jan
(4) |
Feb
(7) |
Mar
(4) |
Apr
|
May
(1) |
Jun
(10) |
Jul
(1) |
Aug
(1) |
Sep
(18) |
Oct
(3) |
Nov
(1) |
Dec
(1) |
2013 |
Jan
(4) |
Feb
(2) |
Mar
(15) |
Apr
(6) |
May
(1) |
Jun
(3) |
Jul
(1) |
Aug
(2) |
Sep
(4) |
Oct
|
Nov
(9) |
Dec
|
2014 |
Jan
(4) |
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
|
Jul
(5) |
Aug
(4) |
Sep
|
Oct
(2) |
Nov
(1) |
Dec
(4) |
2015 |
Jan
(2) |
Feb
(3) |
Mar
(1) |
Apr
(2) |
May
(1) |
Jun
(2) |
Jul
|
Aug
(1) |
Sep
(2) |
Oct
(9) |
Nov
(35) |
Dec
(6) |
2016 |
Jan
(7) |
Feb
(10) |
Mar
(10) |
Apr
(9) |
May
(13) |
Jun
(9) |
Jul
(1) |
Aug
(3) |
Sep
(3) |
Oct
(1) |
Nov
(1) |
Dec
|
2017 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2018 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2019 |
Jan
(1) |
Feb
|
Mar
|
Apr
(2) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2020 |
Jan
(1) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Per W. <pw...@ia...> - 2007-07-18 05:59:01
|
Alas, the debugger integration Dev-C++ is not too good. Do yourself a favour and download one of the available graphical front-ends (such as Insight) for gdb and debug your application outside Dev-C++. You can add a 'Tool' menu item to directly start an external debugging session. /pwm On Tue, 17 Jul 2007, Adam Jones wrote: > I am having problems when debugging a program using Dev C++. The debugger > stops working for some reason, or the system just locks up. > > Has anyone else experienced this problem with the DEV C++ debugger? > > -Adam Jones > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > |
From: Per W. <pw...@ia...> - 2007-07-18 05:52:06
|
EMA System email: pw...@ia... Per Westermark web: http://iapetus.neab.net Vargvaegen 174B phone: +46 70 214 74 48 S-906 42 Umeaa Sweden On Tue, 17 Jul 2007, Adam Jones wrote: > >>Per Westermark wrote: > >>No, the application will not crach for a str[10]; unless the target is an > >>embedded system with extremely small stack - str[10] is smaller than "int > >>a,b,c" on a 32-bit machine... > > You've missed my point completely. For that, I take the blame....... No, I didn't miss the point. I just noted that there isn't a need to test something that can't be tested (there). An auto-allocated str[] will have an address without regard to if the OS has grown the stack yet or not. The OS will not grow the stack until the application tries to access the variables, since the OS doesn't know how much stack the function uses. For code wth more auto variables than what fits in a single memory page, the compiler will have to insert a loop that sequentially touches a byte in every required memory page, to make sure that the first access isn't beyond the stack guard page. I just see many tools in the toolbox. malloc() isn't the only tool suitable for use with arrays. The avoidance of memory leaks and fragmentation, and the excellent locality of reference makes auto variables very good to use. When using very low-end embedded systems, better compilers will normally create a static stack usage tree so the developer will not have to spend too much time on figuring out worst-case stack need besides any ISR. > > >> Don't assume that you know what I think is okay. > > I would never do that. All I do know is what you wrote. You wrote > > >>There are no pointer to test. If the > >>allocation fails (the stack can't fit the variable) then the application > >>will die. > > >From this statement that you made, I assumed that you did not see a point to > checking if the allocation was not successful. > But you made my point later when you stated: > > >>It is a good habit to always check a pointer retrieved from malloc() or > >>new(), just as checking the result from all other functions that may fail. > > This was the only point I was trying to make. Nothing more or less.... > > -Adam Jones > > |
From: Adam J. <aj...@i-...> - 2007-07-18 01:30:21
|
I am having problems when debugging a program using Dev C++. The debugger stops working for some reason, or the system just locks up. Has anyone else experienced this problem with the DEV C++ debugger? -Adam Jones |
From: Adam J. <aj...@i-...> - 2007-07-18 01:24:36
|
>>Per Westermark wrote: >>No, the application will not crach for a str[10]; unless the target is an >>embedded system with extremely small stack - str[10] is smaller than "int >>a,b,c" on a 32-bit machine... You've missed my point completely. For that, I take the blame....... >> Don't assume that you know what I think is okay. I would never do that. All I do know is what you wrote. You wrote >>There are no pointer to test. If the >>allocation fails (the stack can't fit the variable) then the application >>will die. >From this statement that you made, I assumed that you did not see a point to checking if the allocation was not successful. But you made my point later when you stated: >>It is a good habit to always check a pointer retrieved from malloc() or >>new(), just as checking the result from all other functions that may fail. This was the only point I was trying to make. Nothing more or less.... -Adam Jones |
From: Adam J. <aj...@i-...> - 2007-07-18 01:04:34
|
No problem Jonathan, maybe I should have worded it better. But I do agree with you when you stated: >>I would usually set 'large' to 100bytes (personal preference), but if this is a recursuve function, even that much should probably be on the heap instead. Personally, I do the same. Most modern OSes will allocate more stack space on the fly. As I said the example was a trivial one, and I was just trying to make a point, because I see it all the time. A programmer who thinks they can get away with char[10] may then try to get away with char[64000]. I actually saw that in a program that decodes data from a satellite. As you can imagine the software had problems all the time. What was even worse was the this buffer was called recursively, and it was inside of a thread that did not get terminated properly when the user changed channels. The problems did not show up until the software was running for a bit, because the box it was running on had a large amount of memory...... :) -Adam Jones |
From: Jonathan W. <jon...@gm...> - 2007-07-17 22:03:14
|
Ok Adam, I get it now. "...that the system will allocate a char str[10] without checking to see if it can do it with a malloc first." sounded like he should check whether allocating on the stack would work by mallocing it first. Indeed for any large amount of memory, it is safer to allocate on the heap with the malloc family, and then of course, 'large' will depend on the target architecture. Sure thing I wouldn't like satellites hailing down on top of us :) I would usually set 'large' to 100bytes (personal preference), but if this is a recursuve function, even that much should probably be on the heap instead. It seems I'm a bit snappy at the moment, please accept my apologies if I'm being too harsh. Good evening (or whichever it is where you are) Jonathan On 7/17/07, Adam Jones <aj...@i-...> wrote: > > >>Jonathan Wrote: > >>However, Adam you are wrong about the allocation of char str[10]: this > data will be allocated on the stack, along with other local variables. You > can't check whether it failed or >>not: if there's anough room, ok, if > not, > the program will have already crashed (stack overflow) before you can do > anything (this is why we use malloc() for large amounts of >>memory, which > indeed needs checking) > > When you declare Char str[10], you do create it on the stack. But I was > suggesting that he create it on the heap with the Malloc() function. > Please > reread what I posted, it is listed below again: > > >>Adam Wrote: > >>You also assume which is not very good > >>that the system will allocate a char str[10] without checking to see if > it > >>can do it with a malloc first. On memory allocations you need to check > >>first, and if it fails exit your program gracefully. > > Maybe bad wording, but the fact remains that if you are going to allocate > memory, to be safe do it on the heap (using malloc()) instead of the > stack. > That is what I was suggesting. > > I hope this clears up any miscommunications on my part..... > > > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > -- <Morpheus> linux, c'est une question de VI ou de MORE |
From: Adam J. <aj...@i-...> - 2007-07-17 18:13:46
|
>>Jonathan Wrote: >>However, Adam you are wrong about the allocation of char str[10]: this data will be allocated on the stack, along with other local variables. You can't check whether it failed or >>not: if there's anough room, ok, if not, the program will have already crashed (stack overflow) before you can do anything (this is why we use malloc() for large amounts of >>memory, which indeed needs checking) When you declare Char str[10], you do create it on the stack. But I was suggesting that he create it on the heap with the Malloc() function. Please reread what I posted, it is listed below again: >>Adam Wrote: >>You also assume which is not very good >>that the system will allocate a char str[10] without checking to see if it >>can do it with a malloc first. On memory allocations you need to check >>first, and if it fails exit your program gracefully. Maybe bad wording, but the fact remains that if you are going to allocate memory, to be safe do it on the heap (using malloc()) instead of the stack. That is what I was suggesting. I hope this clears up any miscommunications on my part..... |
From: Adam J. <aj...@i-...> - 2007-07-17 16:11:20
|
>>I really don't understand your talk about malloc() and checking for >>sucessful allocation here. >>If doing >> char str = (char*)malloc(10); >>then the allocation may fail, the the application should test: >> if (str == NULL) fail; >>or >> if (!str) fail; >>However, when declaring: >> char str[10]; >>then the only way the application can fail is if the operating system >>can't supply enough stack space. There are no pointer to test. If the >>allocation fails (the stack can't fit the variable) then the >>application will die. The whole point is to be able to exit the program gracefully and not to hard crash your program. As I stated in my post. Here is what I wrote in the post again: >>You also assume which is > >not very good that the system will allocate a char str[10] without > >checking to see if it can do it with a malloc first. On memory > >allocations you need to check first, and if it fails exit your program gracefully. You assume that letting the system crash is okay. That may be true in the desktop world were you have lots of memory and the person can just reboot their system or kill the program. This is not so true in a mission critical environment were a crash is fatal to a multimillion dollar satellite. In those situations when the malloc fails, You can signal a second system to take over, while controllers on the ground figure out what went wrong with the first system. You just can't let the system crash.... You have to handle it. I admit his example is trivial, but it is a good habit to get into and that was my point..... |
From: Jan M. <jan...@vo...> - 2007-07-17 15:03:32
|
Thanks, the compiler wrote also the gets () should not be used. But to be honest I did not know why. But the truth is I have seen it cannot be checked by any chance how many characters will be send to the string. Jan Mura ----- Original Message ----- From: "Per Westermark" <pw...@ia...> To: "Adam Jones" <aj...@i-...> Cc: <dev...@li...> Sent: Tuesday, July 17, 2007 1:36 PM Subject: Re: [Dev-C++] Problems with input > I really don't understand your talk about malloc() and checking for > sucessful allocation here. > > If doing > char str = (char*)malloc(10); > then the allocation may fail, the the application should test: > if (str == NULL) fail; > or > if (!str) fail; > > However, when declaring: > char str[10]; > then the only way the application can fail is if the operating system > can't supply enough stack space. There are no pointer to test. If the > allocation fails (the stack can't fit the variable) then the application > will die. > > > However, you are correct that gets() should not be used. Or more strongly: > SHOULD NEVER BE USED. If doing C-style input, the function to use is > fgets() since it takes an extra parameter to inform about the size of the > input buffer. gets() is one of the hacker dream functions. If gets() is > used, then the application is compromised. > > /pwm > > On Mon, 16 Jul 2007, Adam Jones wrote: > > > >>Hello, > > > > >>I have got a problem I don't understand very much. > > > > >>I have in my code: > > > > >>#include<stdio.h> > > >>int main() > > >>{ > > >>char str[10]; > > > > >>getchar (); > > >>gets (str); > > >>printf ("%s\n", str); > > >>return 0; > > >>} > > > > It would be helpful to all of us if you could explain why you feel it > > necessary to use getchar() the gets() the way you do. What are you trying to > > accomplish by doing it this way. > > getchar() waits for any keypress to continue, and gets will wait until it > > encounters the newline or end of file before continuing. > > > > You also have a potential to corrupt memory here. What happens if the person > > enters a string longer than 10 Char. You also assume which is not very good > > that the system will allocate a char str[10] without checking to see if it > > can do it with a malloc first. On memory allocations you need to check > > first, and if it fails exit your program gracefully. > > > > >>In this case it seems the program is ignoring the "gets ()" command. After > > I press some key and >CR>It stops and doesn't wait for line input. If I do > > not have there the "getchar () I >>can input a line. > > > > If you hit any key and the CR then the single key press goes to getchar() > > the <CR> goes to the gets() which terminates that call. You should just hit > > any key, then type in your string and then hit CR when you are done. The > > getchar() does not require you to hit CR in order for it to accept the key > > press. This should work. > > > > -Adam Jones > > > > > > ------------------------------------------------------------------------- > > This SF.net email is sponsored by DB2 Express > > Download DB2 Express C - the FREE version of DB2 express and take > > control of your XML. No limits. Just data. Click to get it now. > > http://sourceforge.net/powerbar/db2/ > > _______________________________________________ > > Dev-cpp-users mailing list > > Dev...@li... > > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm > > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > > > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > > > __________ Informace od NOD32 2399 (20070714) __________ > > Tato zprava byla proverena antivirovym systemem NOD32. > http://www.nod32.cz > > |
From: Jan M. <jan...@vo...> - 2007-07-17 14:01:42
|
Ok, I write a program which behaves according to the value it get through getchar (kind of a menu). So it can follow several branches, some of them without gets(). Of course I know the str array in this case can be a reason of potential memory leak but I have sent this code only for explainig what I mean or need. I have written all of it should be in a program I am suppose to do and this is just a part of console front-end for testing purposes and just for me. The production front-ends versions will be in a Windows API and Symbian API. So I don't care about some checking in console front-end and there will be no getchar() or gets() in production versions. But thank you for advices. Jan Mura ----- Original Message ----- From: "Adam Jones" <aj...@i-...> To: <dev...@li...> Sent: Monday, July 16, 2007 6:17 PM Subject: Re: [Dev-C++] Problems with input > >>Hello, > > >>I have got a problem I don't understand very much. > > >>I have in my code: > > >>#include<stdio.h> > >>int main() > >>{ > >>char str[10]; > > >>getchar (); > >>gets (str); > >>printf ("%s\n", str); > >>return 0; > >>} > > It would be helpful to all of us if you could explain why you feel it > necessary to use getchar() the gets() the way you do. What are you trying to > accomplish by doing it this way. > getchar() waits for any keypress to continue, and gets will wait until it > encounters the newline or end of file before continuing. > > You also have a potential to corrupt memory here. What happens if the person > enters a string longer than 10 Char. You also assume which is not very good > that the system will allocate a char str[10] without checking to see if it > can do it with a malloc first. On memory allocations you need to check > first, and if it fails exit your program gracefully. > > >>In this case it seems the program is ignoring the "gets ()" command. After > I press some key and >CR>It stops and doesn't wait for line input. If I do > not have there the "getchar () I >>can input a line. > > If you hit any key and the CR then the single key press goes to getchar() > the <CR> goes to the gets() which terminates that call. You should just hit > any key, then type in your string and then hit CR when you are done. The > getchar() does not require you to hit CR in order for it to accept the key > press. This should work. > > -Adam Jones > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > > > __________ Informace od NOD32 2399 (20070714) __________ > > Tato zprava byla proverena antivirovym systemem NOD32. > http://www.nod32.cz > > |
From: Per W. <pw...@ia...> - 2007-07-17 11:45:16
|
Please cut and paste for your example code, so we can be sure that you mean what it looks like. Your example looks like: class Vector {}; struct { Vector col0; Vector col1; Vector col2; Vector col3; }; If your struct is expected to be a type declaration, it can not be anonymous, but must be given a name. How else are you going to declare a variable of that type? If you where planning on directly define a variable of the struct type: struct { Vector col0; Vector col1; Vector col2; Vector col3; } var; then the compiler has an "anchor" to use for constructing the variable of the anonymous data type. /pwm On Tue, 17 Jul 2007, anand wrote: > Hi all, > > I am doing some porting work where I got one anonymous struct as > Namespace adc > { > > Class Vector > { > > } > > struct > { > Vector col0; //here I am gettng error > Vector col1; > Vector col2; > Vector col3; > }; > } > > I am getting error as > > 1012: error: member ' adc::Vector adc::Matrix::<anonymous struct>::col0' > with constructor not allowed in anonymous aggregate > > > Can some one tell me how to solve this:( > > Thanks in Advance > Anand > > > > ----------------------------------------------- > Robosoft Technologies - Come home to Technology > > Disclaimer: This email may contain confidential material. If you were not an intended recipient, please notify the sender and delete all copies. Emails to and from our network may be logged and monitored. This email and its attachments are scanned for virus by our scanners and are believed to be safe. However, no warranty is given that this email is free of malicious content or virus. > > > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > |
From: Per W. <pw...@ia...> - 2007-07-17 11:37:00
|
I really don't understand your talk about malloc() and checking for sucessful allocation here. If doing char str = (char*)malloc(10); then the allocation may fail, the the application should test: if (str == NULL) fail; or if (!str) fail; However, when declaring: char str[10]; then the only way the application can fail is if the operating system can't supply enough stack space. There are no pointer to test. If the allocation fails (the stack can't fit the variable) then the application will die. However, you are correct that gets() should not be used. Or more strongly: SHOULD NEVER BE USED. If doing C-style input, the function to use is fgets() since it takes an extra parameter to inform about the size of the input buffer. gets() is one of the hacker dream functions. If gets() is used, then the application is compromised. /pwm On Mon, 16 Jul 2007, Adam Jones wrote: > >>Hello, > > >>I have got a problem I don't understand very much. > > >>I have in my code: > > >>#include<stdio.h> > >>int main() > >>{ > >>char str[10]; > > >>getchar (); > >>gets (str); > >>printf ("%s\n", str); > >>return 0; > >>} > > It would be helpful to all of us if you could explain why you feel it > necessary to use getchar() the gets() the way you do. What are you trying to > accomplish by doing it this way. > getchar() waits for any keypress to continue, and gets will wait until it > encounters the newline or end of file before continuing. > > You also have a potential to corrupt memory here. What happens if the person > enters a string longer than 10 Char. You also assume which is not very good > that the system will allocate a char str[10] without checking to see if it > can do it with a malloc first. On memory allocations you need to check > first, and if it fails exit your program gracefully. > > >>In this case it seems the program is ignoring the "gets ()" command. After > I press some key and >CR>It stops and doesn't wait for line input. If I do > not have there the "getchar () I >>can input a line. > > If you hit any key and the CR then the single key press goes to getchar() > the <CR> goes to the gets() which terminates that call. You should just hit > any key, then type in your string and then hit CR when you are done. The > getchar() does not require you to hit CR in order for it to accept the key > press. This should work. > > -Adam Jones > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > |
From: Per W. <pw...@ia...> - 2007-07-17 11:31:45
|
You have to think about signed or unsigned data. When you use BCD numbers, i.e. pack digits in nibbles, the most significant packed nibble will behave differently if the "container" byte/word is signed or unsigned, since the mist significant bit of the word is the sign bit. The digit 8 or 9 are the only BCD values (0..9) that have the most significant bit set, so they are the only BCD values what would correspond to a negative value for the "container" word. Try your program again, but use a unsigned char/unsigned short/unsigned int/unsigned long... to store the BCD number. /pwm On Mon, 16 Jul 2007, Jerome Knapp wrote: > /*Hi Everybody- > Im new, wrote this little program to see how I could pack some > bcd bytes for another project. Im curious why I get "ffffff8 _ when I enter 8 > or 9 for the first or 3rd digit. Can some one explain where this comes > from? I can get rid of it with > > printf ("packed value of digits is %2X \n", (digit[i]& 0x0ff)); > > but Im curious where it comes from and why only for 8 or 9, must have to do with bit 3. > > Thanx > Mot > */ > //================================================== > #include <stdio.h> > #include <stdlib.h> > #include <conio.h> > > int i,j =0; > char digit[5]; > > //this program takes in 4 digits from the keyboard and packs them into 2 packed-bcd bytes. > > int main(int argc, char *argv[]) > { > > for (i=0;i<4; i++) {// 4 single digits = two packed bcd bytes > while (!kbhit()); //wait > digit[i]=getch(); // getch gets the char from the buffer > printf("%d",digit[i],"\n"); // echo back > printf(" ascii the value of i is %d\n",i); > } > > //now convert from ascii to hex > for (i=0;i<4; i++) {// 4 single digits = two packed bcd bytes > digit[i]=digit[i]-48; //convert from ascii to decimal > printf("%d",digit[i],"\n"); // echo back > printf(" the value of i is %d\n\n",i); > } > > //now pack the bcd > digit[0]= (digit[0]<<4) | (digit[1]); > digit[1]= (digit[2]<<4) | (digit[3]); > printf ("digits packed are %x %x \n\n", digit[0],digit[1]); > > system("PAUSE"); > return 0; > } > //========================================================== > > |
From: Jonathan W. <jon...@gm...> - 2007-07-17 09:16:13
|
Adam, OK no problem, sorry for the misunderstanding. I'm not a _very_ proeficient gdb user myself... On the other hand if you're using dev-cpp debug mode to 'peek inside', you're using gdb :-) (ok, command line is 1337 but well :-P) You can set breakpoints with dev-cpp also, instead of putting a pause. Indeed, I sure have heard many of these things, and agree we should choose wisely, these being useful in some cases. I know your pain when debugging someone else's code (my worst: crazy indentation and one-letter variables....) I have to use my Amulet of obfuscation, +15 insight :P Have a good day, Jonathan On 7/16/07, Adam Jones <aj...@i-...> wrote: > > Jonathan, > Sorry Jonathan the post was for Arpit Jain, it was not directly at > you personally. By mistake I put your name in instead of Arpit Jain. I do > use system a fair amount to launch other programs or instruct the > operating > system to perform some tasks. I would as stated never use system("pause") > in > a release version of a software. As for gdb I am no fan. If I need to > break > a program to peek at the values of some variables at one point. I will > insert system("pause') just to take a peek instead of using gdb. I am no > gdb > guru, and maybe I should became one. > > As you may already know, over my years of experience I have read > and > hear from many a programmer, you should never have global variables, > #define, goto, etc. I understand their point of view, but if the > programmer > who is programming understands the tradeoffs they are making and using one > of these items solves the problem > and makes the code more readable and maintainable, then use it. > > I personally dislike when I have to debug someone's code and they > have written it in such a fashion that I have to use my secret decoder > ring > :). I do agree with you in principle. > > -Adam Jones > > > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > -- <Morpheus> linux, c'est une question de VI ou de MORE |
From: Jonathan W. <jon...@gm...> - 2007-07-17 09:04:51
|
Hi, Multiple things are happening here: As Adam said, the getchar() will only take one character, the <CR> then gets eaten by the gets(), terminating the string. Also, the gets() will not (and cannot) check the length of the string the user enters against the length of your buffer, therefore mangling your data if the user enters a too-long string. A solution is to use fgets(). See here for an explanation http://www.gidnetwork.com/b-56.html On top of that, you will probably notice with some debugging prints that the letter you type before <CR> is only given to getchar() when you type <CR>. This is because windows (and most OS) only flushes the buffer when lots of data has been sent, or <CR> is pressed. There must be a way to change this behavior, but I'm not familiar with it (try looking for unbuffered stdin) This modification shows what happens with your program: try typing "azerty<CR>" and see what happens #include<stdio.h> int main() { char str[10]; char c; puts("press a key"); c = getchar(); printf("you pressed %c\n",c); puts("enter a string"); gets (str); printf ("you typed %s\n", str); return 0; } However, Adam you are wrong about the allocation of char str[10]: this data will be allocated on the stack, along with other local variables. You can't check whether it failed or not: if there's anough room, ok, if not, the program will have already crashed (stack overflow) before you can do anything (this is why we use malloc() for large amounts of memory, which indeed needs checking) Cheers, Jonathan On 7/16/07, Adam Jones < aj...@i-...> wrote: > > >>Hello, > > >>I have got a problem I don't understand very much. > > >>I have in my code: > > >>#include<stdio.h> > >>int main() > >>{ > >>char str[10]; > > >>getchar (); > >>gets (str); > >>printf ("%s\n", str); > >>return 0; > >>} > > It would be helpful to all of us if you could explain why you feel it > necessary to use getchar() the gets() the way you do. What are you trying > to > accomplish by doing it this way. > getchar() waits for any keypress to continue, and gets will wait until it > encounters the newline or end of file before continuing. > > You also have a potential to corrupt memory here. What happens if the > person > enters a string longer than 10 Char. You also assume which is not very > good > that the system will allocate a char str[10] without checking to see if it > can do it with a malloc first. On memory allocations you need to check > first, and if it fails exit your program gracefully. > > >>In this case it seems the program is ignoring the "gets ()" command. > After > I press some key and >CR>It stops and doesn't wait for line input. If I > do > not have there the "getchar () I >>can input a line. > > If you hit any key and the CR then the single key press goes to getchar() > the <CR> goes to the gets() which terminates that call. You should just > hit > any key, then type in your string and then hit CR when you are done. The > getchar() does not require you to hit CR in order for it to accept the key > press. This should work. > > -Adam Jones > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > -- <Morpheus> linux, c'est une question de VI ou de MORE |
From: anand <ana...@ro...> - 2007-07-17 05:04:00
|
Hi all, I am doing some porting work where I got one anonymous struct as Namespace adc { Class Vector { } struct { Vector col0; //here I am gettng error Vector col1; Vector col2; Vector col3; }; } I am getting error as 1012: error: member ' adc::Vector adc::Matrix::<anonymous struct>::col0' with constructor not allowed in anonymous aggregate Can some one tell me how to solve this:( Thanks in Advance Anand ----------------------------------------------- Robosoft Technologies - Come home to Technology Disclaimer: This email may contain confidential material. If you were not an intended recipient, please notify the sender and delete all copies. Emails to and from our network may be logged and monitored. This email and its attachments are scanned for virus by our scanners and are believed to be safe. However, no warranty is given that this email is free of malicious content or virus. |
From: Jerome K. <jj...@ya...> - 2007-07-16 17:40:21
|
/*Hi Everybody- Im new, wrote this little program to see how I could pack some bcd bytes for another project. Im curious why I get "ffffff8 _ when I enter 8 or 9 for the first or 3rd digit. Can some one explain where this comes from? I can get rid of it with printf ("packed value of digits is %2X \n", (digit[i]& 0x0ff)); but Im curious where it comes from and why only for 8 or 9, must have to do with bit 3. Thanx Mot */ //================================================== #include <stdio.h> #include <stdlib.h> #include <conio.h> int i,j =0; char digit[5]; //this program takes in 4 digits from the keyboard and packs them into 2 packed-bcd bytes. int main(int argc, char *argv[]) { for (i=0;i<4; i++) {// 4 single digits = two packed bcd bytes while (!kbhit()); //wait digit[i]=getch(); // getch gets the char from the buffer printf("%d",digit[i],"\n"); // echo back printf(" ascii the value of i is %d\n",i); } //now convert from ascii to hex for (i=0;i<4; i++) {// 4 single digits = two packed bcd bytes digit[i]=digit[i]-48; //convert from ascii to decimal printf("%d",digit[i],"\n"); // echo back printf(" the value of i is %d\n\n",i); } //now pack the bcd digit[0]= (digit[0]<<4) | (digit[1]); digit[1]= (digit[2]<<4) | (digit[3]); printf ("digits packed are %x %x \n\n", digit[0],digit[1]); system("PAUSE"); return 0; } //========================================================== |
From: Adam J. <aj...@i-...> - 2007-07-16 16:18:06
|
>>Hello, >>I have got a problem I don't understand very much. >>I have in my code: >>#include<stdio.h> >>int main() >>{ >>char str[10]; >>getchar (); >>gets (str); >>printf ("%s\n", str); >>return 0; >>} It would be helpful to all of us if you could explain why you feel it necessary to use getchar() the gets() the way you do. What are you trying to accomplish by doing it this way. getchar() waits for any keypress to continue, and gets will wait until it encounters the newline or end of file before continuing. You also have a potential to corrupt memory here. What happens if the person enters a string longer than 10 Char. You also assume which is not very good that the system will allocate a char str[10] without checking to see if it can do it with a malloc first. On memory allocations you need to check first, and if it fails exit your program gracefully. >>In this case it seems the program is ignoring the "gets ()" command. After I press some key and >CR>It stops and doesn't wait for line input. If I do not have there the "getchar () I >>can input a line. If you hit any key and the CR then the single key press goes to getchar() the <CR> goes to the gets() which terminates that call. You should just hit any key, then type in your string and then hit CR when you are done. The getchar() does not require you to hit CR in order for it to accept the key press. This should work. -Adam Jones |
From: Adam J. <aj...@i-...> - 2007-07-16 15:22:35
|
Jonathan, Sorry Jonathan the post was for Arpit Jain, it was not directly at you personally. By mistake I put your name in instead of Arpit Jain. I do use system a fair amount to launch other programs or instruct the operating system to perform some tasks. I would as stated never use system("pause") in a release version of a software. As for gdb I am no fan. If I need to break a program to peek at the values of some variables at one point. I will insert system("pause') just to take a peek instead of using gdb. I am no gdb guru, and maybe I should became one. As you may already know, over my years of experience I have read and hear from many a programmer, you should never have global variables, #define, goto, etc. I understand their point of view, but if the programmer who is programming understands the tradeoffs they are making and using one of these items solves the problem and makes the code more readable and maintainable, then use it. I personally dislike when I have to debug someone's code and they have written it in such a fashion that I have to use my secret decoder ring :). I do agree with you in principle. -Adam Jones |
From: Jan M. <jan...@vo...> - 2007-07-16 12:04:05
|
Hello, I have got a problem I don't understand very much. I have in my code: #include<stdio.h> int main() { char str[10]; getchar (); gets (str); printf ("%s\n", str); return 0; } In this case it seems the program is ignoring the "gets ()" command. After I press some key and >CR>It stops and doesn't wait for line input. If I do not have there the "getchar () I can input a line. It runs in Windows console (Command Prompt). I feel it is some stupid error of me but I don't know where Thank you Jan Mura |
From: Jonathan W. <jon...@gm...> - 2007-07-16 08:28:46
|
Hi, Indeed, using system("pause") at the end of your program isn't too much of a problem, however, I don't agree that it is better than getchar(). > Using system("pause") to stop execution to aid in debugging an application makes a lot of sense. Especially if you choose not to use gdb to debug your code. What sense does it make? If there is a good reason, maybe you can convince me. I don't see what link to gdb there is, since the result of both alternatives is the same. > It is in the language for a reason. Indeed, system() is in the language to allow a program to easily call another without all the fork/exec whatnot, when it isn't necessary. But this only makes sense when the other program called has some kind of added value, such as performing a _non-trivial_ operation Likewise, PAUSE is in the O.S. for a very good reason: allowing batch files to wait for the user. I am not against system(), nor PAUSE; but I don't think using them together to perform the same thing as getchar() makes sense. > Jonathan my advice to you is to understand how to use the language efficiently [...] I believe you were talking to Arpit Jain here rather, but I shall suppose it was for me, and so: I think I have learned in my past years of experience how to use C quite efficiently. I am surely no guru, but I'm pretty content, I also believe I can still learn. Indeed, people may 'make a religion' of (not) coding some way or other, but in this case it's different; the system(pause) issue has a backing arguments, not just "BECAUSE you don't use it!" I also have confidence in the designers and community. Microsoft included PAUSE with good reason. The designers included system() for a reason, they included the 'goto' keyword for a reason (and no, I'm not going to develop on that further than it should be used when more structured control is not efficient). On the other hand, 'system("pause")' isn't part of the standard or the language but is a confluence of two worlds, and the language has an alternative to it. Every part of the (language, tools, etc) has indeed it's pros and cons, and we should all learn to know them and work with them. In this case, the pros are ['is does what it says'], and the cons are ['it is totally inefficient']. My choice is quickly made. Arpit Jain, your choice is in your hands. I have used system("pause") many times in the past, and it didn't bite. Just bear in mind the problem it could be, especially when using system() for other things. Adam, I would be honoured to share your knowledge. Yours, Jonathan On 7/14/07, Adam Jones <aj...@i-...> wrote: > > >>There are two global solutions: > >>a. make your program wait for a keypress before exiting > >>b. open a console, go to the folder, and run the program from there. > > There is a third choice and that is to use the system("pause") it is very > easy to use and very appropriate for what he is doing in the Hello world > program. He must make sure that he includes the <cstdlib> header. > > >>a. is is easier for you to use while developping, since you can start > the > prog from DevC++ and see the result. > > >>A correct way of doing this is to call getchar(); > >>this will try to read a char from the input, and will wait until it gets > one. much better. > > >An EVIL way is to call system("pause"); You can read why here: > http://www.gidnetwork.com/b-61.html > > I read this link along with others that this person posted. Having a > system("pause") call at the end of the program poses no problem, because > the > next call is to exit. Especially in a HELLO WORLD program. Using > system("pause") in a release version would not make sense. Using > system("pause") to stop execution to aid in debugging an application makes > a > lot of since. Especially if you choose not to use gdb to debug your code. > It is in the language for a reason. Use it when it is appropriate. > > >>Jonathan > >>On 7/13/07, arpit jain <arp...@gm...> wrote: > >>im new 2 programing & i have been trying to learn C, & for that i > started > using bloodshed dev c++5.0 but what im not getting is when i run the > program > the software doesnt show >>the result but makes an application file (DOS > based) for e.g. that HELLO WORLD program's output just gets flashed in the > command prompt which im myself unable to see properly >>as it flashes > hardly even for a second. could u pls. help me on this.........???? > > Jonathan my advice to you is to understand how to use the language > efficiently. You will find people telling you never to program this way or > never to program that way. But they make a religion out of it. I have > confidence in the designers who developed C\C++, and the ANSI community > that > oversees the ANSI standard for C\C++. You use what is best for the problem > you are trying to solve. Every keyword/STL function, etc has it's pros and > cons. You need to understand what those are and program accordingly. > > -Adam Jones > > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > -- <Morpheus> linux, c'est une question de VI ou de MORE |
From: Adam J. <aj...@i-...> - 2007-07-14 01:44:10
|
>>There are two global solutions: >>a. make your program wait for a keypress before exiting >>b. open a console, go to the folder, and run the program from there. There is a third choice and that is to use the system("pause") it is very easy to use and very appropriate for what he is doing in the Hello world program. He must make sure that he includes the <cstdlib> header. >>a. is is easier for you to use while developping, since you can start the prog from DevC++ and see the result. >>A correct way of doing this is to call getchar(); >>this will try to read a char from the input, and will wait until it gets one. much better. >An EVIL way is to call system("pause"); You can read why here: http://www.gidnetwork.com/b-61.html I read this link along with others that this person posted. Having a system("pause") call at the end of the program poses no problem, because the next call is to exit. Especially in a HELLO WORLD program. Using system("pause") in a release version would not make sense. Using system("pause") to stop execution to aid in debugging an application makes a lot of since. Especially if you choose not to use gdb to debug your code. It is in the language for a reason. Use it when it is appropriate. >>Jonathan >>On 7/13/07, arpit jain <arp...@gm...> wrote: >>im new 2 programing & i have been trying to learn C, & for that i started using bloodshed dev c++5.0 but what im not getting is when i run the program the software doesnt show >>the result but makes an application file (DOS based) for e.g. that HELLO WORLD program's output just gets flashed in the command prompt which im myself unable to see properly >>as it flashes hardly even for a second. could u pls. help me on this.........???? Jonathan my advice to you is to understand how to use the language efficiently. You will find people telling you never to program this way or never to program that way. But they make a religion out of it. I have confidence in the designers who developed C\C++, and the ANSI community that oversees the ANSI standard for C\C++. You use what is best for the problem you are trying to solve. Every keyword/STL function, etc has it's pros and cons. You need to understand what those are and program accordingly. -Adam Jones |
From: Jan M. <jan...@vo...> - 2007-07-13 12:25:49
|
Thank you very much boys & boys. I am a little bit better C-er again. Jan Mura ----- Original Message ----- From: "Jonathan Winterflood" <jon...@gm...> To: "Per Westermark" <pw...@ia...> Cc: "Jan Mura" <jan...@vo...>; <dev...@li...> Sent: Tuesday, July 10, 2007 6:43 PM Subject: Re: [Dev-C++] Compilation of multiple files > Indeed, the preprocessor directives you use aren't well placed: > > Firstly: > You use > #ifndef __stdio_h__ > #include<stdio.h> > #define __stdio_h__ > #endif > in your files as to not include stdio.h multiple times. > however, stdio.h (and any properly built .h file) already deals with this > issue (mostly the same way you did): > > something.h: > #ifndef __something_h__ > // > // body of something.h > // > #define __something_h__ > #endif > > source and header files using something.h: > #include "something.h" > > Secondly: > This mecanism only prevents the multiple inclusion of the .h > file on the same compilation run, but every .c file is compiled seperately > and then linked together to save effort (imagine recompiling a 300+ file > project (or even a 10-file one) just to change one small thing in one file > :D ) > > Jonathan > > > > __________ Informace od NOD32 2391 (20070711) __________ > > Tato zprava byla proverena antivirovym systemem NOD32. > http://www.nod32.cz > |
From: Abilash S. M. <abi...@wi...> - 2007-07-13 09:57:47
|
U might want to add getch(); at the end of the main function. For the getch to work u will need to import conio.h . Abilash Sankar Mohan, Wipro Technologies. _____ Abilash Sankar Mohan, Wipro Technologies. _____ From: dev...@li... [mailto:dev...@li...] On Behalf Of arpit jain Sent: Friday, July 13, 2007 3:07 PM To: dev...@li... Subject: [Dev-C++] a query... im new 2 programing & i have been trying to learn C, & for that i started using bloodshed dev c++5.0 but what im not getting is when i run the program the software doesnt show the result but makes an application file (DOS based) for e.g. that HELLO WORLD program's output just gets flashed in the command prompt which im myself unable to see properly as it flashes hardly even for a second. could u pls. help me on this.........???? |
From: Jonathan W. <jon...@gm...> - 2007-07-13 09:55:23
|
Hi, The basic, simple program won't have a graphical user interface, only input/output via the console/terminal/DOS box. There are two global solutions: a. make your program wait for a keypress before exiting b. open a console, go to the folder, and run the program from there. a. is is easier for you to use while developping, since you can start the prog from DevC++ and see the result. A correct way of doing this is to call getchar(); this will try to read a char from the input, and will wait until it gets one. much better. An EVIL way is to call system("pause"); You can read why here: http://www.gidnetwork.com/b-61.html Jonathan On 7/13/07, arpit jain <arp...@gm...> wrote: > > im new 2 programing & i have been trying to learn C, & for that i started > using bloodshed dev c++5.0 but what im not getting is when i run the program > the software doesnt show the result but makes an application file (DOS > based) for e.g. that HELLO WORLD program's output just gets flashed in the > command prompt which im myself unable to see properly as it flashes hardly > even for a second. could u pls. help me on this.........???? > > |