mersenneforum.org  

Go Back   mersenneforum.org > Extra Stuff > Programming

Reply
 
Thread Tools
Old 2012-02-12, 20:02   #144
ewmayer
2ω=0
 
ewmayer's Avatar
 
Sep 2002
República de California

19×613 Posts
Default

Quote:
Originally Posted by CRGreathouse View Post
What about random numbers, time/date, and other things that will change without regard to the source?
I believe the distinction y'all are circling around is "deterministic or not." This same distinction is a key parameter for RNGs (random number generators). Sometimes one needs genuinely unpredictable numbers (or initial seeds); but in many cases one needs "deterministically random" numbers for e.g. software QA purposes.

Reading from an uninitialized memory location (in the lingo, a UMR - uninitialized memory read) is clearly nondeterministic - sure, you may get the same result over multiple runs of the program, if those re-use the same memory space and nothing else writes the memloc in question in the interim. (Often when trying to track down a crash or other bug which eventually proves due to a UMR, one in fact relies on that near-term-repeatability aspect over multiple debugger runs). But there's a good reason there are dedicated code tools (e.g. Purify, valgrind) designed to ferret out nasties such as UMRs.

Last fiddled with by ewmayer on 2012-02-12 at 20:03
ewmayer is offline   Reply With Quote
Old 2012-02-12, 20:23   #145
Ralf Recker
 
Ralf Recker's Avatar
 
Oct 2010

101111112 Posts
Default

Quote:
Originally Posted by ewmayer View Post
Reading from an uninitialized memory location (in the lingo, a UMR - uninitialized memory read) is clearly nondeterministic - sure, you may get the same result over multiple runs of the program, if those re-use the same memory space and nothing else writes the memloc in question in the interim. (Often when trying to track down a crash or other bug which eventually proves due to a UMR, one in fact relies on that near-term-repeatability aspect over multiple debugger runs). But there's a good reason there are dedicated code tools (e.g. Purify, valgrind) designed to ferret out nasties such as UMRs.
Uninitialized memory reads and valgrind: That reminds me of the Debian OpenSSL incident...

Last fiddled with by Ralf Recker on 2012-02-12 at 20:28
Ralf Recker is offline   Reply With Quote
Old 2012-02-12, 22:07   #146
Dubslow
Basketry That Evening!
 
Dubslow's Avatar
 
"Bunslow the Bold"
Jun 2011
40<A<43 -89<O<-88

1C3516 Posts
Default

Code:
while((c = getc(stdin)) != EOF){
              if(cp == &in_line[LINELNG-1] || c == '\n'){
                      /*
                       stuff to end string*/
              }
              else
                      *cp++ = c;
}
Oh, after seeing that the first time, it really feels dirty, but at the same time, it's oh-such-a-beautiful line of code.

Last fiddled with by Dubslow on 2012-02-12 at 22:07
Dubslow is offline   Reply With Quote
Old 2012-02-13, 04:42   #147
axn
 
axn's Avatar
 
Jun 2003

5,087 Posts
Default

Quote:
Originally Posted by Dubslow View Post
I guess for printing then, I just need to specify more than 6 significant digits.

Now, though we are agreed that %lf is a double for scanf, why does 3.141592653589 get truncated to 3.141593, even though the former should fit inside a double?
Nothing is getting truncated excepted for the printed output!!!! And you know why _that_ is happening.
axn is offline   Reply With Quote
Old 2012-02-13, 04:55   #148
chalsall
If I May
 
chalsall's Avatar
 
"Chris Halsall"
Sep 2002
Barbados

2·67·73 Posts
Default

Quote:
Originally Posted by axn View Post
Nothing is getting truncated excepted for the printed output!!!! And you know why _that_ is happening.
There are reasons why teachers must have much patience....

(Or, at least, the good ones. )
chalsall is online now   Reply With Quote
Old 2012-02-13, 06:06   #149
Dubslow
Basketry That Evening!
 
Dubslow's Avatar
 
"Bunslow the Bold"
Jun 2011
40<A<43 -89<O<-88

3·29·83 Posts
Default

Quote:
Originally Posted by axn View Post
Nothing is getting truncated excepted for the printed output!!!! And you know why _that_ is happening.
I'm sorry, I do sometimes do smart things!!! I swear!

Dubslow is offline   Reply With Quote
Old 2012-02-13, 06:49   #150
axn
 
axn's Avatar
 
Jun 2003

10011110111112 Posts
Default

Quote:
Originally Posted by Dubslow View Post
I'm sorry, I do sometimes do smart things!!! I swear!

I believe ya.
axn is offline   Reply With Quote
Old 2012-02-16, 03:01   #151
Dubslow
Basketry That Evening!
 
Dubslow's Avatar
 
"Bunslow the Bold"
Jun 2011
40<A<43 -89<O<-88

3×29×83 Posts
Default

As for that pointer business, I know understand why what I did was no different from just using standard array notation. As such, I rewrote the LL program, by which I mean I made better use of actual pointers.

http://dubslow.tk/random/ll.txt

On the other hand, I think I also went a bit overboard with the pointer arithmetic. One went from one extreme to the other...

Edit: I think the old one is faster...

Last fiddled with by Dubslow on 2012-02-16 at 03:28
Dubslow is offline   Reply With Quote
Old 2012-02-16, 04:51   #152
axn
 
axn's Avatar
 
Jun 2003

13DF16 Posts
Default

Quote:
Originally Posted by Dubslow View Post
On the other hand, I think I also went a bit overboard with the pointer arithmetic. One went from one extreme to the other...
Code:
/* This would definitely be better with indices than pointers.	*/
I agree. That loop is the worst loop in the whole program to be chosen for pointer arithmetic.
axn is offline   Reply With Quote
Old 2012-02-16, 06:14   #153
Dubslow
Basketry That Evening!
 
Dubslow's Avatar
 
"Bunslow the Bold"
Jun 2011
40<A<43 -89<O<-88

722110 Posts
Default

Two typos in one quote. I am a boss.

*Went from one extreme to the other....

*with indices rather than (with) pointers.
Dubslow is offline   Reply With Quote
Old 2012-02-21, 22:00   #154
emily
 
Feb 2012
Athens, Greece

47 Posts
Default

It's also worth noting that there is the D programming language which might be of interest if you want something similar to C++ but with some features of C# and Java. http://en.wikipedia.org/wiki/D_(programming_language)
emily is offline   Reply With Quote
Reply

Thread Tools


All times are UTC. The time now is 23:30.


Fri Aug 6 23:30:45 UTC 2021 up 14 days, 17:59, 1 user, load averages: 3.76, 3.84, 3.94

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.