|
Oh i figured mine out. Turns out pipes are one way, and i was writing to the wrong end.
|
# ? May 1, 2008 14:29 |
|
|
# ? May 23, 2024 03:50 |
|
Vanadium posted:It says
|
# ? May 1, 2008 15:38 |
|
TSDK posted:The clue's in the message then: don't cast to uint. Pointer and int are usually the same size though... edit: even if they are different sizes, he's setting next to 0. If he were only printing 4 out of the 8bytes used in the pointer, he still shouldn't be getting 64. I'm blaming printf. You could prove that your printf statement is to blame by doing an: [code] if(node->next == 0) { printf("I, printf, suck wang\n"); } Since you're using g++, try std::cout. vanjalolz fucked around with this message at 16:17 on May 1, 2008 |
# ? May 1, 2008 16:10 |
|
One of your printf formats is being ignored (probably because it doesn't like "%Lfx") so it's reading the wrong thing off the stack. And use %p instead of casting pointers to something else.
|
# ? May 1, 2008 16:33 |
|
vanjalolz posted:Pointer and int are usually the same size though... NEVER assume this. You have no idea how many times this comes up. If you want your code to compile on 64-bit, DO NOT ever assume this. Like, ever. Ever.
|
# ? May 1, 2008 16:35 |
|
I'm wondering if anything like this exists:code:
I'm asking because I've implemented about 80% of it but I'd love to find out it's already in boost and I'm just terrible at finding it.
|
# ? May 1, 2008 17:02 |
|
more falafel please posted:NEVER assume this. You have no idea how many times this comes up. If you want your code to compile on 64-bit, DO NOT ever assume this. Like, ever. Or at least use uintptr_t .
|
# ? May 1, 2008 17:16 |
|
vanjalolz posted:I don't like the look of that, you're defining a struct Node then you're typedef'ing over it. You're using g++ so you dont need the type def anyway, change it to vanjalolz posted:Are you on a 64 bit system? I think the proper way to printf pointers is %p. I don't get it, though. The new codepad output is still correct, but mine is still nonsense. code:
MrVacBob posted:One of your printf formats is being ignored (probably because it doesn't like "%Lfx") so it's reading the wrong thing off the stack.
|
# ? May 2, 2008 01:32 |
|
elevatordeadline posted:The reason for the typedef is because this was at one point C code elevatordeadline posted:>: a.exe
|
# ? May 2, 2008 15:04 |
|
This totally would not have happened if you were actually using C++ properly
|
# ? May 2, 2008 16:15 |
|
Andrei Alexandrescu posted:Indeed, where there are ellipses, there's not much C++ left.
|
# ? May 2, 2008 16:17 |
|
Andrei Alexandrescu posted:Indeed, where there are ellipses, there's not much C++ left. Unless it's C++0x.
|
# ? May 2, 2008 20:47 |
|
elevatordeadline posted:I don't get it, though. The new codepad output is still correct, but mine is still nonsense.
|
# ? May 2, 2008 21:17 |
|
vanjalolz posted:Then you should do typedef struct Node_t { .. } Node; code:
code:
code:
code:
|
# ? May 2, 2008 23:51 |
|
Mustach posted:There's not really a "should" here. All of these work for bypassing the struct namespace: When using all except the last, make sure the struct's real name is different from the one created by the typedef.
|
# ? May 3, 2008 02:29 |
|
HB posted:When using all except the last, make sure the struct's real name is different from the one created by the typedef. Why?
|
# ? May 3, 2008 02:33 |
|
Vanadium posted:Why? To avoid a conflict, that's how I remember learning it v:)v I just tried it and apparently I have been misled all these years.
|
# ? May 3, 2008 02:39 |
|
HB posted:To avoid a conflict, that's how I remember learning it v:)v Just don't do the following in C++ (works in C): code:
|
# ? May 3, 2008 02:48 |
|
HB posted:When using all except the last, make sure the struct's real name is different from the one created by the typedef. That's what I was getting at. You don't want to be at the mercy of the compiler with something like this. Be explicit and show that there is a difference between the struct and the typedef.
|
# ? May 3, 2008 07:18 |
|
From the boostcon thread:The Red Baron posted:To keep this post slightly more on-topic, how long should we expect to have to wait before C++0x is incorporated in most major compilers, assuming that they actually manage to get the standard out next year? For GCC I'm sure it won't be long at all, but it'd suck if we had to wait an entire Visual Studio cycle before the vcpp compiler got upgraded The gcc guys list a bunch of features they already implement at http://gcc.gnu.org/gcc-4.3/cxx0x_status.html, and Herb Sutter has alluded that MSVC already implements a bunch of stuff as well. To be honest, I expect MSVC to have a "complete" implementation sooner than gcc.
|
# ? May 3, 2008 12:18 |
|
I've got a question about an error I've been getting and it's driving me nuts because I just can't figure out what is the problem. This is the error in MSVC++; error C2143: syntax error : missing ';' before '*' I've gotten these kinds of errors before and there has always been a logical way out of them, but this time I just can't see what the problem is so maybe you guys can help me out. Here's my code; http://pastebin.com/m23d01ab6 If you want me to paste more files, then let me know.
|
# ? May 3, 2008 13:16 |
|
You are including levelclass.h in your playerclass.h, so it is used before it is defined. Either move line 40 to 52+, or completely remove it. The ; before * message is usually part of a bigger message that says that a type can not be found. edit: To make it clearer: LevelClass uses PlayerClass, but PlayerClass.h includes LevelClass.h BEFORE it defines what PlayerClass is, therefore the compiler trips up trying to figure out what playerclass is in levelclass. vanjalolz fucked around with this message at 13:24 on May 3, 2008 |
# ? May 3, 2008 13:20 |
|
vanjalolz posted:You are including levelclass.h in your playerclass.h, so it is used before it is defined. drat, this has been getting me for the past few hours and that's all it was. Probably happened because I've been playing around with the player and level class to get the communication flow just right and accidently forgot to delete that #include. Thanks a lot!
|
# ? May 3, 2008 17:09 |
|
vanjalolz posted:Be explicit and show that there is a difference between the struct and the typedef. Struct tags occupy a different namespace than typedef names, so it's like what HB found out: there won't be any conflict if a typedef name is the same as a struct tag. With struct Blah { int x; };, the name of the struct isn't "Blah", it's "struct Blah".
|
# ? May 3, 2008 17:13 |
|
Mustach posted:the name of the struct isn't "Blah", it's "struct Blah". In C, yes. What about c++ (which he is using to compile)? Isn't Blah a synonym for struct Blah? Its also a synonym for a typedef... edit: both of which mean the same thing! Ok I get it, but I still disagree. Its messy and confusing! the standard is typedef struct x_t { ... } x, *px; so stick with it
|
# ? May 3, 2008 19:07 |
|
vanjalolz posted:edit: both of which mean the same thing! Ok I get it, but I still disagree. Its messy and confusing! the standard is typedef struct x_t { ... } x, *px; so stick with it Whose standard is that?
|
# ? May 3, 2008 22:20 |
|
ehnus posted:Whose standard is that? Thats the way it is in most win32 headers.
|
# ? May 3, 2008 23:20 |
|
ehnus posted:Whose standard is that? I've always seen structs typedef'd either like that (append _t), or with an underscore on either side of the struct name. I think it's just the defacto standard, like using i and j for index variables. No one's going to eviscerate you for not using it, but it's just what "usually" is used.
|
# ? May 3, 2008 23:36 |
|
Well, I think people will probably eviscerate you if you do it in C++.
|
# ? May 4, 2008 00:21 |
|
I've got a template question. I have two functions:code:
What I want is the second function to basically be code:
However when I have both functions, and invoke the first as: code:
code:
If it makes a difference this is with g++ (GCC) 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2) edit: For reference: code:
6174 fucked around with this message at 00:48 on May 5, 2008 |
# ? May 5, 2008 00:39 |
|
6174 posted:I've got a template question. I have two functions: Your trouble is right at the start. These two functions have the same signature: arbitrary_partition(T, vector<T>). There's no way for the compiler to distinguish between them. You'll either need to give the functions different names, or change the parameters they accept.
|
# ? May 5, 2008 01:00 |
|
ColdPie posted:Your trouble is right at the start. These two functions have the same signature: arbitrary_partition(T, vector<T>). There's no way for the compiler to distinguish between them. You'll either need to give the functions different names, or change the parameters they accept. That would explain it. I thought the return value was considered for deciding what to do with overloaded functions. I guess not, and 7.4.1 of Stroustrup explains why.
|
# ? May 5, 2008 01:19 |
|
For a programming project, I need to write a real basic interpreter for a scheme like language. All it really needs to do is be able to handle basic primitives, if statements, literals, numbers, local variable bindings..and that's probably about it. I was hoping I could download the source code for something similar as a reference point, but so far I've been unable to download anything that it isn't wayyyy too complex..does anyone know where I might be able to download a basic c++ interpreter like this?
|
# ? May 5, 2008 02:09 |
|
Soldat posted:For a programming project, I need to write a real basic interpreter for a scheme like language. All it really needs to do is be able to handle basic primitives, if statements, literals, numbers, local variable bindings..and that's probably about it. I was hoping I could download the source code for something similar as a reference point, but so far I've been unable to download anything that it isn't wayyyy too complex..does anyone know where I might be able to download a basic c++ interpreter like this? Are you constrained to a C/C++ host language? Because Scheme is really easy to write an interpreter for, but C and C++ are really not the greatest languages for the task, and any non-trivial interpreter in them is going to be at least fairly complex.
|
# ? May 5, 2008 02:25 |
|
ShoulderDaemon posted:Are you constrained to a C/C++ host language? Because Scheme is really easy to write an interpreter for, but C and C++ are really not the greatest languages for the task, and any non-trivial interpreter in them is going to be at least fairly complex. Unfortunately I am constrained to c++. The interpreter itself will be somewhat trivial I think, everything else I've found has been way too extensive. Any other suggestions?
|
# ? May 5, 2008 02:33 |
|
Soldat posted:Unfortunately I am constrained to c++. The interpreter itself will be somewhat trivial I think, everything else I've found has been way too extensive. Any other suggestions? Well, TinyScheme is the C version I would suggest studying. The opcode evaluator uses some occasional magic because it's designed for embedded systems, but the garbage collector and handling of closures and continuations is about as straightforward as you're likely to see outside of a textbook. It's only about 5300 lines of code for a very large portion of the R5RS. The only really tricky bits to reading it are that the author occasionally scatters his structure definitions around in the code; a program like cscope will probably help a lot. Oh, and it uses lots of conditional compilation, but if that bothers you just run it through a preprocessor step or manually remove the features you don't care about.
|
# ? May 5, 2008 02:54 |
|
Here's a tutorial for writing a small Scheme interpreter in Scheme. I think it would be straightforward to take most of the concepts and re-implement them in C++. For parsing, you could look into boost::spirit, which lets you specify grammars in EBNF-like syntax. Given the syntactical simplicity of Scheme you could probably get a parser up and running relatively easily.
|
# ? May 5, 2008 04:33 |
|
I have a Data Structures final today (in about 4 hours) and I am trying to get the gist of what everything is about. One of the big problems I had this semester was trying to wrap my head around Recursion. I had this example question for a review: Q: Write a recursive function for f(x) = f(x-1) + 4x + 3 where f(0) = 1. Is this correct? code:
|
# ? May 5, 2008 14:48 |
|
notMordecai posted:I have a Data Structures final today (in about 4 hours) and I am trying to get the gist of what everything is about. One of the big problems I had this semester was trying to wrap my head around Recursion. I had this example question for a review: Just kind of at a first glance (about to run out the door to school myself), this looks all right. I'd add in a check to make sure x isn't negative -- that'd create an infinite loop. Depending on exactly how the requirements are worded, I'd throw the check for <=0 at the start: code:
Anyways looks fine to me. Good luck.
|
# ? May 5, 2008 15:24 |
|
|
# ? May 23, 2024 03:50 |
|
Recursion-wise that looks right - the only problem is "4(x)" won't compile, it's "4*x".ColdPie posted:Just kind of at a first glance (about to run out the door to school myself), this looks all right. I'd add in a check to make sure x isn't negative -- that'd create an infinite loop. Depending on exactly how the requirements are worded, I'd throw the check for <=0 at the start: This is always a good idea, and falls under "always check for unexpected inputs". The function will never get down to a negative number while it's recursing, but it'll break if someone else calls "recurse(-1)". The easiest and best fix is to change it to "unsigned int recurse(unsigned int x)" so it's not even possible to pass it a negative number.
|
# ? May 5, 2008 16:16 |