389 Posted Topics
Re: > pipelining and branch prediction at the CPU level maybe??? Branch prediction seems like a pretty good candidate. Note that the if condition `data[c] >= 128` will randomly switch between being true and false when the array is unsorted, but when it is sorted it will be false consistently until … | |
Re: A pointer is the address of a variable (or the address of an array slot, the address of a struct member etc.). For as long as the pointed-to variable is alive, you can access its value by dereferencing the pointer. | |
Re: > Abstract classes are sort of the C++ flavor of what is traditionally called "Interfaces" in the Java/C# OOP terminology. I'd say they're the C++ flavor of what Java and C# call abstract classes. A C++ abstract class wouldn't translate to a Java/C# interface unless all the members are purely … | |
Re: Because you're using `i++`/`++i` as a statement on its own without doing anything with its value. The side-effects of `++i` and `i++` are the same, only the value differs. So if you don't use the value, there is no observable difference. | |
Re: > how can I delete the file if it just becomes unlinked? When you say "delete", what exactly do you mean? Scrambling the file? Because when most people say "delete", they mean "removing the file system entry", which is exactly what remove/unlink does. > Also I haven't tried to yet, … | |
Re: Can you explain a bit what you code does any why you think it should do more than discarding one character after it sees a `{`? > You need to shove it onto the stack so you can push and pop the curly brackets. DFAs don't have stacks, so I … | |
Re: To iterate two arrays in parallel, you can use: array1.zip(array2) do |element1, element2| # ... end | |
Re: First of all `ptr` is an array (of pointers), not a pointer. So you can't assign to it. Second of all, even if it were a pointer, it wouldn't be an int pointer, so casting the result of `malloc` to `int*` is wrong because that's the wrong type (also: don't … | |
Re: The problem is `c "and the new skill value is"`: there's only a space between `c` and the string - no comma. | |
Re: In Visual Studio you can press Ctrl + F5 or Shift + F5 (I don't remember which one) instead of just F5 to run your application in a console window that does not close. In most other IDEs the output will either show up in a tab or a window … | |
Re: Put your code in a method that takes the hash as an argument, then define the hash after the method and call the method at the end. | |
Re: When `i` is 0, we get `arr[num[0]] += 1`. `num[0]` is 1, so we get `arr[1] += 1`. By the same logic we get `arr[4] += 1` when i is 1 and so on. So no, it doesn't increase each element of `arr` by 1. Rather it increases each element … | |
Re: As the error message correctly points out, it is indeed not a inside a loop. In fact there is no loop anywhere in your function. | |
Re: What is `random`? It's not a standard function. Did you define it yourself or does it come with Turbo C++? Anyway this `random` function probably needs to be seeded just like the standard `rand` function does. So if you don't provide a seed, you'll get the same sequence of random … | |
Re: Also asked (and answered) [here](http://www.dreamincode.net/forums/topic/345231-pointer-question-of-function/). | |
Re: > it gives an error message at line 12 What's the error message? | |
Re: > A node needs to point to another node, not to a DATA. It does. `node<DATA>*` is a pointer to a node. > Why not just use the following (apparently satisfactory) structure I haven't read the book, but presumably the solution presented hides the implementation of the nodes, whereas your … | |
Re: You do not use parsing algorithms to generate a list of tokens. The list of tokens is the input to the parsing algorithm. The output of the algorithm is generally an AST or some kind of intermediate representation of the code (or in some cases even the end product of … | |
Re: Pointers are iterators (random access iterators to be specific) and they are in fact commonly used as such. For example `std::vector<T>` uses `T*` in most (possibly all) implementations (except in the case of `vector<bool>`, which is a special case). On the other hand there are many iterators that aren't pointers. … | |
Re: > I suspect the OP is compiling it as C++ where string is very likely to cause issues due to potentially being exposed as a type name. Why would it be likely to cause issues in C++? `g++` doesn't complain about the OP's code, even if I add `#include <string>` … | |
Re: Yes, `cup1` is an object (or rather it's a variable referring to an object - just like `cup2`). The biggest difference between `cup1` and `cup2` is that, if the `Coffee` class defines public methods in addition to those declared in `CoffeeInterface`, you will be able to call those on `cup2`, … | |
Re: I think the problem is that it does not recognize `uint8_t` as a type name because the `stdint.h` header was not included. That would explain why the error happens "before 'r'", rather than on line 1 (also I believe that (AVR-)GCC is the only compiler that you can use to … | |
Re: Is `elements` a collection of string pointers or of strings? Judging from the error messages I'd say it's the latter, so your lambda needs to take a string or string reference as its argument. Since `destroy` takes a pointer, you'll have to pass a pointer to your string to it. … | |
Re: `num1obj` has not been initialized and is thus neither pointing on the stack nor on the heap - it is pointing nowhere at all. Therefore dereferencing it invokes undefined behavior. Note that this is in no way specific to objects. If you dereferenced an int pointer that you did not … | |
![]() | Re: Can you clarify what exactly you don't understand? The arrow means assignment, `for i <- x to y` means a for loop that iterates `i` from `x` to `y` and everything else seems to be the same as in C (i.e. `/` is division, `[]` is array access etc.). One … |
Re: An immutable object is an object whose state can't be changed in any way through it's public interface. So it has no public variables and none of its public methods change any of its variables. One example of such objects are strings. You'd use those object like you'd use any … | |
Re: If you declare a variable as being of type `Object`, you're not going to be able to call any methods on that object other than the ones defined in the `Object` class (or pass it as an argument to any method that takes something other than `Object` as their argument) … | |
Re: You're counting all multiples of 15 twice (once as multiples of 3 and once as multiples of 5). | |
Re: You need the `def` keyword to define methods in Ruby. The reason that you need a keyword for this is that the creator of Ruby decided that was the most convenient syntax for method definitions. | |
Re: Also you need to forward-declare your factorial function or define it before the main function. | |
Re: > Instead of creating an array and a pointer just create a pointer and allocate memory. Why do you find that preferable in this case? str = (char *)malloc(sizeof(char)*20); // for 20 characters There's no need to cast the return type of `malloc`. Void pointers are implicitly castable to any … | |
Re: VLAs are perfectly valid in C99 and "GNU89" - the only reason it wouldn't work with gcc/MinGW is if you explicitly set the standard to C89. And it doesn't work in VS because Visual Studio's C support is completely outdated. Oh and I should mention that this question has also … | |
Re: > The problem is that it is taking away too much, double the cost System.out.println("Calc: " + this.curGold + " - " + goldValue + " = " + (this.curGold -= goldValue)); this.curGold -= goldValue; In the above code you execute `this.curGold -= goldValue` twice (once in the print statement … | |
Re: How exactly did you install GHC? Did you install anything Haskell-related other than the main GHC package? And what's the exact error message you're getting? | |
Re: > I believe that H(t1) stands in for a list of all the synonymes of t1 According to the paper it stands for "a set of tuples (h, f), where h is a hypernym and f is the number of times the algorithm has found evidence for it". So `n` … | |
Re: > I don't know of any built in pow function in Haskell Why don't you count `^` as a pow function? > powthing :: Int -> Int Unless you have a good reason to prefer `Int` over `Integer` (like you know for a fact that your use of `Integer` is … | |
Re: Let's say you have 25c and can use the 10c and 5c coins. Since 15 is greater than 10, you may use a 10c coin. If you do, you have 15c left (for which you again may or may not use another 10c coin). If you don't, you still have … | |
Re: When declaring a variable, preceding the variable name with a `*` makes it a pointer. Preceding it with a `&` is illegal (in C - in C++ it makes the variable a reference). In an expression `&` takes a variable and produces a pointer to that variable, whereas `*` takes … | |
Re: `copyOfX` is not a copy of `x` - it's a reference that refers to the same object that `x` refers to. If you want a copy, you need to explicitly create a copy, for example by invoking a copy constructor (assuming one is defined) like this: X copyOfX = new … | |
Re: > I know that NP problems can't be solved in polynomial time. Since NP is a superset of P that can't possibly be true for all problems in NP. It is likely that NP-hard can't be solved in polynomial time, but that's an open question (NP ?= P), which has … | |
Re: You can also use `for animal, noise in` instead of `for tpl in`. Then you can use `animal` and `noise` instead of `tpl[0]` and `tpl[1]` respectively. | |
Re: The relation is that the record is stored on the stack. PS: This happens for all function calls (that aren't inlined by the compiler), not just recursive ones. | |
Re: Are you sure that the warning doesn't say "makes integer from pointer" rather than "makes pointer from integer"? I have no idea why it would say the latter for your code and my compiler at least says the former. The reason for that warning is that the elements of `argv` … | |
Re: Do you think it's true or false? What have you trieed to prove or disprove it? What's the definition of big-Oh - how would `2^(2^n)` need to relate to `2^n` for `2^(2^n)` to be in `O(2^n)`? | |
Re: In your example code you only push one tree into the vector, so that's not enough to reproduce your problem. My guess is that in your real code you have a loop around lines 3 to 10. So at the end of each iteration of the loop, `myRBTreeCopy` goes out … | |
Re: I'm not quite sure I understand the question. You're simulating the game of life, so, at each step, you have a grid containing the live and dead cells, right? So just iterate over that grid and count the cells that are alive. | |
Re: > When ever a multiplication code is called the compiler will perform inner addition operation. What? It might have been common for CPUs to not support multiplication over 30 years ago, but I doubt very much that any such CPUs exist now. So there's no reason for a compiler to … | |
Re: The error is because you call `sub2` first with `hd z` and then with `tl z` as the third argument. `hd z` and `tl z` have different types: If `z` is a list of `foo`s, then `hd z` is a `foo` and `tl z` is a `foo list`. For `foo` … | |
Re: > '^' is a special character ONLY when used as the first character within square brackets `^` means "beginning of the line" outside of square brackets, so it does need to be escaped. You're right about `_` though. |
The End.