|
Avenging Dentist posted:2) he's already said this is just for debugging, which is a totally legit reason to do something like this.
|
# ? Jan 30, 2010 22:22 |
|
|
# ? May 19, 2024 03:38 |
|
Avenging Dentist posted:From your link: http://www.codeproject.com/KB/cs/Mandelbrot_set.aspx#premain1 (not how I'd do it) Ok I sort of got it working now. places on the perimeter are colored but most all the exterior is black. Is it the equation for mu or is it the way it assigns color values?
|
# ? Jan 30, 2010 22:30 |
|
Fedaykin posted:Ok I sort of got it working now. places on the perimeter are colored but most all the exterior is black. Is it the equation for mu or is it the way it assigns color values? Look at the screenshot in the article. It's the color gradient. An easy way to get different colors would be to use HSL and then convert it to RGB.
|
# ? Jan 30, 2010 22:49 |
|
defmacro posted:EDIT: I guess to clarify: I want a kernel-space interface to the iptables rules in the kernel. This interface should create rules that can ONLY be removed by the kernel-space interface. You could write a kernel module using netfilter.h that did some iptables-ish processing of packets. Other than that, I don't know of a way to do what you want.
|
# ? Jan 31, 2010 16:12 |
|
I'm working on a project that involves, among other things, reading and comparing a bunch of floating point numbers from some files. This presents some obvious difficulties, especially because the input format specification implicitly rejects the transitivity of equality of floating point numbers. I'm not sure of the best strategy for dealing with this. Discarding float-point equality transitivity sounds like a terrible idea, but maybe I'm thinking about it the wrong way. I had the idea of doing fp comparisons using an epsilon while also keeping track of every fp number I read and, if a transitivity violation is detected, declaring the entire conversion (the program converts files) undefined and bailing, but I don't really know what would work best. I'm sure this isn't a novel problem but I don't know where to look for solutions.
|
# ? Jan 31, 2010 22:50 |
|
GrumpyDoctor posted:I'm working on a project that involves, among other things, reading and comparing a bunch of floating point numbers from some files. This presents some obvious difficulties, especially because the input format specification implicitly rejects the transitivity of equality of floating point numbers. Can you use fixed point in this situation?
|
# ? Feb 1, 2010 01:10 |
|
GrumpyDoctor posted:I'm working on a project that involves, among other things, reading and comparing a bunch of floating point numbers from some files. This presents some obvious difficulties, especially because the input format specification implicitly rejects the transitivity of equality of floating point numbers. Is this right after it denies the fundamental theorem of algebra, but before it gets into its discussion of the continuum hypothesis? EDIT: No, I guess those would be explicit rejections. OBLIGATORY EDIT 2: Which I assume you would know something about.
|
# ? Feb 1, 2010 01:35 |
|
Anyone have a link to the 'Cantor did wtc' screed
|
# ? Feb 1, 2010 01:37 |
|
rjmccall posted:Is this right after it denies the fundamental theorem of algebra, but before it gets into its discussion of the continuum hypothesis? For what it is worth, the relation GrumpyDoctor described (two floating point numbers are related if and only if they are within some epsilon of each other) is not an equivalence relation because that relation is not transitive. GrumptyDoctor, I'd have to know more about what you are doing to suggest a solution, but it is possible (likely for an appropriate epsilon) that your data set won't violate transitivity. I'd start by writing a script that checks for such violations (sort your data then check). Only if you found violations would I worry about it.
|
# ? Feb 1, 2010 04:52 |
|
litghost posted:Can you use fixed point in this situation? It wouldn't solve my problem - even if I can trust my own representations of the data, I can't trust their input representations. 6174 posted:For what it is worth, the relation GrumpyDoctor described (two floating point numbers are related if and only if they are within some epsilon of each other) is not an equivalence relation because that relation is not transitive. This is basically what I was thinking, so it's probably what I'll go with. If I find a violation I can bitch at the upstream guy. Internally I was thinking about using Boost::Rational - anyone have any thoughts?
|
# ? Feb 1, 2010 21:31 |
|
A friend of mine has written a bunch of code in C++ which takes about an hour to run each time he runs it. Unfortunately it is not working correctly. He knows that the problems are occurring towards the end of the run and would like to start debugging at that point. Is there any way for him to save the status of the code about 50 minutes in and start debugging from that point each time? Hopefully my question makes sense.
|
# ? Feb 2, 2010 22:40 |
|
Jose Cuervo posted:A friend of mine has written a bunch of code in C++ which takes about an hour to run each time he runs it. Unfortunately it is not working correctly. He knows that the problems are occurring towards the end of the run and would like to start debugging at that point. Is there any way for him to save the status of the code about 50 minutes in and start debugging from that point each time? Hopefully my question makes sense. He can generate a core dump at that point in the program, and tell his debugger to launch that instead of the executeable itself, see gdb(1) gcore(1) core(5). If the program does file IO or network IO after that point on handles that were opened prior to that point, you may need to build a wrapper to get its filehandles setup as it expects, but that's an edge case.
|
# ? Feb 2, 2010 22:51 |
|
You may also find gdb 7's support for reverse debugging useful, though I've not tried it yet so I don't know how useful it really is.
|
# ? Feb 3, 2010 02:16 |
|
I am writing a program in C which needs to translate network values (big-endian for every input to this program) to host values (little-endian on my machine) in a number of places. I use ntohl and ntohs for doing so. Unfortunately, in one place I have to take in a big-endian value which is 3 bytes long and turn it into an integer in the host's endianness. I can't find any library functions which do this, so I've written my own (below). This function gets passed a 3-byte long character array, puts them in the proper order in an integer and returns that value. The return value should be padded with 0x00 in the most significant byte. I know this works on little-endian machines, as I've tested it. I was wondering if this code will work on big-endian machines as well, but I have none available to me to test it on. code:
Also, is there a better way to do this?
|
# ? Feb 5, 2010 03:31 |
|
nightchild12 posted:Also, is there a better way to do this? It's somewhat clearer if you abuse aliasing. This is arguably unsafe, but I can't think of any compilers that won't do the right thing. code:
|
# ? Feb 5, 2010 05:41 |
|
nightchild12 posted:Also, is there a better way to do this? code:
|
# ? Feb 5, 2010 05:52 |
|
For those not following the blog, Clang now self-hosts. http://blog.llvm.org/2010/02/clang-successfully-self-hosts.html
|
# ? Feb 5, 2010 13:21 |
|
What happens when an int pointer is cast to an int? I am trying to understand this bit of code. Before I saw this, I thought that an int pointer was just an int that happened to be a memory address, but I am finding that this is not the case.code:
|
# ? Feb 6, 2010 18:19 |
|
If you add to a pointer, you offset it by (a multiple of) the size of the type it points to, not by the value you added. So q + 16 will be a memory address 16 * sizeof( int ) bytes further along, not 16 bytes further along. When you shove the pointer into an int, and add to the int instead, all you are doing is increasing the value of the int. (Ignoring the fact that shoving a pointer into an int isn't the best thing in the world to be doing.) digibawb fucked around with this message at 18:35 on Feb 6, 2010 |
# ? Feb 6, 2010 18:32 |
|
Pointer arithmetic is done in increments of the size of the type the pointer points to, cf. this slight modification to your code http://codepad.org/SvWHBqWY
|
# ? Feb 6, 2010 18:33 |
|
use intptr_t yo
|
# ? Feb 6, 2010 18:56 |
|
Thanks! That's awesome. I had no idea that's how that worked. I guess this is why operator overloading is confusing? edit: By the way, how would I have found that out if it weren't for the forums? I was trying to find the int* documentation somewhere online to find out what the + operator does, but I had no luck. I am usually a java person so there's a javadoc for everything, is there a resource like that for C++?
|
# ? Feb 6, 2010 19:56 |
|
man(1) covers the C standard library and POSIX, although for very fundamental poo poo like this you probably want to bang through K&R and Koenig&Moo
|
# ? Feb 6, 2010 20:00 |
|
Vanadium posted:use intptr_t yo Yeah, that code as-is could do weird things on a 64-bit system since you would be shoving a 64-bit pointer into a 32-bit integer.
|
# ? Feb 6, 2010 21:44 |
|
I've got a program that needs to use the equivalent of ntohl, but for 64 bit. I only have a little-endian machine to test on at the moment, so can someone verify for me this works correctly on a big-endian machine?code:
|
# ? Feb 8, 2010 02:47 |
|
I've been playing around with this for a while. How do I get getaddrinfo to give me the IP-address, or rather, the IPv4-address as a valid 32-bit integer? I could use gethostbyname, but the manual recommends avoiding it.
functional fucked around with this message at 05:11 on Feb 8, 2010 |
# ? Feb 8, 2010 03:42 |
|
getaddrinfo is for being agnostic as to IPv4 vs IPv6. If you specifically want IPv4, just use gethostbyname. But if you really want to use getaddrinfo, just pull the address-as-a-number out of the sockaddr_in that you get from an IPv4 result, read ip(7) for documentation of that structure.
|
# ? Feb 8, 2010 03:52 |
|
ShoulderDaemon posted:getaddrinfo is for being agnostic as to IPv4 vs IPv6. If you specifically want IPv4, just use gethostbyname. Got it. The magic trick is learning that the sockaddr you get back can be cast to a sockaddr_in if you know it's IPv4. Also, I needed ntohl. functional fucked around with this message at 04:33 on Feb 8, 2010 |
# ? Feb 8, 2010 04:26 |
|
functional posted:Got it. The magic trick is learning that the sockaddr you get back can be cast to a sockaddr_in if you know it's IPv4. Also, I needed ntohl. And you can determine what type of sockaddr you have by looking at the sa_family field.
|
# ? Feb 8, 2010 06:18 |
|
At what value do (single) floats lose integer precision?
|
# ? Feb 9, 2010 08:05 |
|
Contero posted:At what value do (single) floats lose integer precision? For IEEE floats, any integer with absolute value less than or equal to 2significand can be represented exactly. So, for 32-bit floats with a 24-bit significand, 224 = 16777216.
|
# ? Feb 9, 2010 08:19 |
|
Is it possible for read/write to a regular file to ever successfully return less than the bytes requested, barring possibly being interrupted by a signal, if I know the size of the file? e.g. code:
|
# ? Feb 9, 2010 08:45 |
|
lol 10 bux posted:Is it possible for read/write to a regular file to ever successfully return less than the bytes requested, barring possibly being interrupted by a signal, if I know the size of the file? It could be truncated by another process, maybe NFS errors could cut the read short too.
|
# ? Feb 9, 2010 09:19 |
|
lol 10 bux posted:I'm trying to determine if I have to keep a loop everywhere I want to do a simple read/write to make sure the operation fully completes. In general, there are a wide variety of error conditions that can cause a partial read, and you cannot really predict or prevent them. However, they are exceptional, and essentially none of them* can be corrected by repeating the read in a loop. So you should just check the return of read, and if it isn't correct, don't bother retrying the read - just abort with an error, because retrying won't be any better. *Exactly one error condition from read - EAGAIN - will be potentially solved by retrying the read. But EAGAIN will only come up if you specifically ask for it by entering nonblocking mode, and even then you shouldn't stick a loop around your read because you really need to do something like a select instead.
|
# ? Feb 9, 2010 09:28 |
|
Signals won't result in truncated disk I/O either.
|
# ? Feb 9, 2010 09:30 |
|
pseudorandom name posted:Signals won't result in truncated disk I/O either. Yes they can (in POSIX).
|
# ? Feb 9, 2010 09:41 |
|
Can I do an mmap write to stdout? If so, how? Passing 1 as a file descriptor gives me an error.
|
# ? Feb 11, 2010 05:44 |
|
functional posted:Can I do an mmap write to stdout? If so, how? Passing 1 as a file descriptor gives me an error. If you redirect stdout to a file, and your shell does an arguably weird thing by opening that file in read/write mode instead of write-only mode, then you will be able to mmap stdout. In general, you can only mmap files or sufficiently file-like (must be random-seekable and have a backing store) descriptors) descriptors, and you must have read permission on the descriptor. Edit: What are you trying to do? There's probably a better way. Also, although I doubt it matters in this case, you should always specify the error you get instead of "an error", which is possibly the least helpful thing you can say. Posting the actual code you're trying to use is also generally a good idea.
|
# ? Feb 11, 2010 05:58 |
|
I have a question involving OpenGL. So let's say that I want to draw a line segment, but instead of just simply drawing the line segment, the segment is "drawn" using really big 5x5 pixels. How would I go from (10,10) to (20,20) with only two 5x5 pixels drawn instead of a bunch of normal pixels, using Bresenham's linescan conversion algorithm? Complicating things even more is trying to draw from the center of each tiny portion of where the 5x5 pixel is supposed to be. Drawing the line segment normally gives me no trouble whatsoever, but to do this confuses me. code:
|
# ? Feb 11, 2010 14:14 |
|
|
# ? May 19, 2024 03:38 |
|
Whilst farting I posted:How would I go from (10,10) to (20,20) with only two 5x5 pixels drawn instead of a bunch of normal pixels, using Bresenham's linescan conversion algorithm? Complicating things even more is trying to draw from the center of each tiny portion of where the 5x5 pixel is supposed to be. code:
|
# ? Feb 11, 2010 14:32 |