|
how exactly do << and >> work? I know they are bitwise rotation to the left or right, but I think they eat up a carry that is 1>>1 = 0 instead of - max integer.
|
# ¿ Feb 17, 2008 04:35 |
|
|
# ¿ Apr 20, 2024 07:14 |
|
when i do a left shift, does the left most bit get sent to some carry register? on x86 machines, what would be the name of it? I guess same would go for the right shift and right most digit. I know how this works in PIC Micro controller, but I have no idea of how i would go about using it in C or assembler for x86.
|
# ¿ Feb 17, 2008 09:14 |
|
illamint posted:I'm fairly new to C++ and I'm wondering what the regular expression library du jour is. For a project in my CS class, we have to parse fairly large files (right now I'm going line-by-line with the regular expression "^([A-Za-z0-9]+),([A-Za-z0-9]*),([A-Za-z0-9]*),(s?f?|f?s?);$"), and I'm using regex.h which is unfortunately incredibly slow. I see that there's Boost.Regex, but we have to hand in our source code at the end of the project and I'm not sure that it's feasible to merge the Boost shared library stuff into my makefiles just for this. Should I just parse it by hand? Is there a better solution? I'm used to being able to just go to the Java or Python docs and glance at the syntax in the manual but I'm having kindof a hard time doing that with C++. use lex DFAs are harder to implement in C++ than writing a lexer that can do the same thing. Lexer outputs DFA anyway. Just define your reg expression and associate a rule for when lexer finds it (that is what C++ code to execute), and voila, you are done. Entheogen fucked around with this message at 14:53 on Mar 7, 2008 |
# ¿ Mar 7, 2008 00:37 |
|
Milde posted:There's erase(iterator pos) and erase(iterator first, iterator last). The latter erases a range of elements. You want the former (and with an iterator). http://www.cppreference.com/ That website is also really awesome for general references on C/C++ standard libraries and other stuff. I use it a lot.
|
# ¿ Mar 9, 2008 19:30 |
|
Thug Bonnet posted:No, that's what I'm asking! I'm just kind of curious, honestly. But how would the program know "where it is" in memory, how large it is, etc. Also, I assume it's not necessarily contiguous.. I believe the OS allocates a chunk of RAM to the program and maps it using virtual memory. That is for program the memory may start at 0x0000 or something but then OS maps it to real memory. I am not quite sure. I think for C++ programs "how large it is" can grow as the program continues to allocate new memory on heap, so the OS must be adding to its virtual page. I know for java you have to actually set a maximum amount of heap memory you will use, but not for C++. Thug Bonnet posted:Identical in what sense? I think he means that start of program's heap address is like 0x000 (from program's perspective) ( i have no idea what it actually is ), and is the same for all threads that OS is executing. Entheogen fucked around with this message at 22:32 on Mar 10, 2008 |
# ¿ Mar 10, 2008 22:29 |
|
i just use iterators for FOREACH in C++ and use signed integers for everything else. code:
|
# ¿ Jul 4, 2008 01:00 |
|
hey, i never had issues with C++ iterators and STL containers. I use Java for bigger projects because its easier to work with. C++ is good for small programs when you just want to calculate some stuff though. oh ok, is all the fuss about because many functions take size_t instead of int? i don't see how this could become an issue unless you are dealing with large indecies. Entheogen fucked around with this message at 01:54 on Jul 4, 2008 |
# ¿ Jul 4, 2008 01:50 |
|
sarehu posted:Here's an algorithm that scales better with respect to integer size. I don't think it's a good idea to use a macro. What does L stand for in there?
|
# ¿ Jul 4, 2008 19:33 |
|
what does even bits mean? is it an AND operation with something that has 1's only in even places so the product only has 1's in even positions? vvvv thanks that makes perfect sense now vvvvv For what purposes would you want to use evenbits function for? Entheogen fucked around with this message at 20:01 on Jul 4, 2008 |
# ¿ Jul 4, 2008 19:52 |
|
Mustach posted:That macro re-evalutates its first argument 15 times. doesn't this get done at compile-time, so by the time it compiles its super fast code since it doesn't have to do an extra function call?
|
# ¿ Jul 7, 2008 13:55 |
|
Mustach posted:Only if the argument is a constant expression. There stil won't be an "extra" function call since the macro just expands to a single statement, but EVEN_BITS_W(f()); expands to oh ok, i see what you are saying. even though macro is replaced by pre-compiler with whatever it is defined to, if data is a function call it will be evaluated 15 times.
|
# ¿ Jul 7, 2008 14:44 |
|
Insurrectum posted:I'm talking about time differences in the 10 to 100s of milliseconds http://www.cppreference.com/stddate/index.html I believe time returns time in mili seconds, or it might be micro. In any case it should be enough for timing your programs.
|
# ¿ Jul 13, 2008 05:25 |
|
Insurrectum posted:I tried that and all I could get was seconds. Here's the solution I found: did you try using clock() method? that should definitely have granularity finer than 1 second. what does your GetTickCount() do? do you just increment some variable in your loop somewhere in PROGRAM?
|
# ¿ Jul 13, 2008 07:45 |
|
Avenging Dentist posted:Check Boost.Turing, it's in the Boost Sandbox. hahah, this is a joke, right? Drx Capio posted:What's an easy way to determine if an arbitrary program will halt? Is there a library for it? If you are asking this seriously, then the answer is no. There is no general algorithm that will take another arbitrary algorithm and determine if it will ever halt or not. Look up halting problem on google if you don't believe me.
|
# ¿ Jul 13, 2008 21:10 |
|
double post
Entheogen fucked around with this message at 21:12 on Jul 13, 2008 |
# ¿ Jul 13, 2008 21:10 |
|
Nubile Cactus posted:Anyone have a list of c++ exercises, from relatively simple to slightly complex? Looking to brush up on c++ and I've always found exercises the best way to do it, but the book I'm using doesn't have any. You can try doin practice programing competitions problems in C++. It will force you to laern more C++ and STL and also improve algo skills. Probably not that great for OOP learning tho. I did a bunch of TopCoder problems using C++/STL and I found that it boosted my knowledge of STL quite a bit, since I ended up using it a lot.
|
# ¿ Jul 15, 2008 19:55 |
|
how exactly does one link statically instead of dynamically in c++? the only way to link dynamically would be against a DLL or SO file? when I include .h files in my C++ program and it is linked against a .lib file is that static linking by default?
|
# ¿ Jul 17, 2008 12:23 |
|
I used pointers before to switch between two arrays that contain same types. such as code:
If I did something like this: code:
Also is there a way to get around using some confusing rear end referencing and dereferncing operators when dealing with iterators on containers that contain pointers themselves? such as code:
Entheogen fucked around with this message at 21:02 on Jul 20, 2008 |
# ¿ Jul 20, 2008 20:57 |
|
Zombywuf posted:std::swap will usually be optimised to do this internally, i.e. it woun't copy the contents of the vectors, just swap the pointers to the internal arrays. It's also better from a readability perspective, i.e. swap(A, B) does what it says. does it copy in the example I had? I thought that the pointer just changed address from either A or B. I didn't realize it was copying their entire contents each time I did curr = & A
|
# ¿ Jul 21, 2008 14:58 |
|
floWenoL posted:Unless someone overrode operator& for vectors somewhere before. I don't understand. Is not & a referencing operator. So it gets you address of whatever it is on its right? What is going on here, I am getting confused. vvvvvvvvvvvvvvvvvvvvvv OK, so STL overloaded & operator for vectors to copy them? Entheogen fucked around with this message at 23:06 on Jul 21, 2008 |
# ¿ Jul 21, 2008 21:29 |
|
Sabotaged posted:Okay, I've been using a lot of STL lately, and it scares me a lot because I don't really understand how something like an stl string manages its memory. I am probably wrong, but I think string allocates itself on stack if you allocate it on stack and just wraps char * inside of it. It deletes itself when it is popped from stack or when you delete it yourself assuming you put it into dynamic memory.
|
# ¿ Jul 22, 2008 04:23 |
|
you need to store your numbers in an array not an int. int is for just one number that is represented with 4bytes usually. Also you are assigning evennumbers to store numbers % 2 before you even read store numbers from file. The reason it outputs only 1s is because you are only printing out one variable which never changes, and got set to 1 the last time you modified it. That is because the last number to be assigned to evennumber is 2 % 2 == 0 which is true or 1. Also don't do while ( !outFile.eof() ) to print stuff to that file stream. You only need to check for that when you are reading it in. oh and to catch errors, like whether files were succefully opened or not, you can just surround the whole thing with try catch block and catch std::exception & exc. I am not sure if my code takes care of new line and carriage return characters for input. If you run into problems you can use .ignore function, but the way you should use it is code:
just do something like this. I use vector here which is STL class for dynamic arrays (they can be resized easily). code:
Entheogen fucked around with this message at 02:23 on Jul 23, 2008 |
# ¿ Jul 23, 2008 02:13 |
|
is there a way to determine endianess of a floating point number at runtime in either C++ or Java? Is this something that cannot be determined from data alone? I am reading a binary file and would like to know if I have to reverse the bits or not.
|
# ¿ Aug 1, 2008 02:09 |
|
Avenging Dentist posted:Why wouldn't you do that at compile time? What do you mean? The idea is that I will have binary files as input and some of them might have IEEE floating point numbers in one endianness and another in different one. Instead of forcing user to choose which one they would like the file to be read as, I was wondering if there is an automatic way of doing this, but my suspicion is there is not because otherwise there would have to be some sort of meta-data describing the contents of file, and there is no such data, its just floating point numbas.
|
# ¿ Aug 1, 2008 03:36 |
|
|
# ¿ Apr 20, 2024 07:14 |
|
Avenging Dentist posted:That's stupid. I am reading in files made from Fortran where it is reverse. But I would also like my software to work with files generated with normal endianness. Ideally I don't want to rely on any sort of meta-data in the file itself to be able to successfully read it in and visualize it. I think I will try NaN and Infinite values perhaps or try to look for those bits that can never be true if its correct endianess. In worst case scenario I will just let the end-user decide what endianess they want before they read in the file.
|
# ¿ Aug 1, 2008 05:04 |