Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

roomforthetuna posted:

But it's pretty contrived and unnecessary, since you could get that behavior by just having a non-virtual TreeNode::BeginClimb() function or something in addition to the pure virtual one.
If templates are involved I suppose you could have a situation where it needs to have the same name, but you'd have to actively try pretty hard to ever run into that.

Adbot
ADBOT LOVES YOU

Hughlander
May 11, 2005

roomforthetuna posted:

Someone asked earlier but not very clearly, are you in the right configuration? It's possible that the preprocessor definitions that you see in the file are for debug or release build only, and you're looking at the other one.

Yep, everything looks right, and the Preprocessor defines that are listed in the dialog do not show up in the vcproj under the <tool VCCCompilerTool or whatever I posted originally section. :iiam: Everything works, I'm just not clear on how it got to this state in the first place. I checked the history of the vcproj and it got added back when the vcproj was for either 2005 or even 2003, maybe it's just something with the conversion didn't bring it along. Or maybe the dialog is stripping it out since it's using the $() environmental variable bullshit.

Gerblyn
Apr 4, 2007

"TO BATTLE!"
Fun Shoe
You checked the history in version control? Could it have been caused by a merge error, maybe? I've had weird things happen with XML files being merged with SVN before...

Are there maybe two tool="VCCCompilerTool" nodes and it's ignoring the second one?

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

That Turkey Story posted:

All compliant compilers do. You can always define the body of a pure virtual function. The Microsoft extension he was talking about was that you can define them inside the class definition -- normally you have to define them outside of the definition.

Yes. Although it's really dumb that you can do this at all.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!
If you build boost on a 64-bit machine, using MSVC 9.0 (which is Visual C++ 2008), and you don't specify anything about address-model, will it default to building a 64-bit version or 32-bit?

Asking because I recently changed my compilation machine to a new one, Windows 7 64-bit, and now my project using libtorrent-rasterbar, which uses boost, is behaving erratically. I haven't changed any settings or any code that should be libtorrent-related, and all the libraries are the same version as I was using before, so I'm grasping at straws for what might now be going wrong. The only thing I've changed other than the dev environment is the torrent file, but the new one works fine with uTorrent, and is generated by libtorrent-rasterbar, so I can't see how that would be causing a problem. (And stepping through libtorrent code in debug mode it appears to be handling the file just fine, I just lose track of it where it calls into boost::bind asynchronously - at that point it should be connecting to my webserver and doesn't seem to be doing so.)

roomforthetuna fucked around with this message at 00:11 on Aug 14, 2011

pseudorandom name
May 6, 2007

You can't mix 32-bit and 64-bit code on AMD64, so it flat out wouldn't link if boost spontaneously started being built 64-bit.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!
Thanks - turned out the problem was it wasn't the same version of libtorrent after all, and the new version was broken in its dealing with URL seeds (as well as having some crash bugs with logging enabled when compiled with MSVC). So I emailed the guy fixes for the problems I found, and reverted to using the older version for myself. What a frustrating waste of a day.

To contribute something that might be interesting to others, the "offsetof" macro, even the adjusted for C++ one Microsoft uses, causes a crashing exception in the event of something like:
code:
class Something {
 public:
  OtherClass& a;
};

int main() {
 int n=offsetof(Something, a);
}
Is there any way you could define this that would work to get the offset of a reference value? I imagine this must work in some compiler, that or the libtorrent guy didn't test his latest version with logging enabled at all.

pseudorandom name
May 6, 2007

That generates a warning but works correctly in both clang and gcc.

edit: And it doesn't have anything to do with a being a reference, the problem is that the C++ standard says that offsetof() on a non-POD type isn't allowed. OTOH, offsetof() will work correctly on a great many flavors of non-POD types, so people still use it. Apparently MSVC will poo poo itself, though.

pseudorandom name fucked around with this message at 02:05 on Aug 14, 2011

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!
It compiles without a warning in MSVC, and then crashes on execution (which is actually what I'd expect, since using the address operator on a reference value gives the address of what is referenced, not the address of the reference value).

Just had a look on a gcc system and it looks like it's not a preprocessor definition at all there, but a true operator like sizeof (at least, I can't find it being #defined anywhere in the include dir)

pseudorandom name
May 6, 2007

stddef.h is special, and you'll find it somewhere similar to /usr/lib/clang/2.8/include/stddef.h or /usr/lib/gcc/x86_64-redhat-linux/4.6.0/include/stddef.h.

And they both #define offsetof(a, b) __builtin_offsetof(a, b)

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!
So back to the question I was asking, is there any way syntactically (short of a compiler builtin that figures it out for you) to get the offset to a reference value in a class? (Assuming you don't know what else is in there so you can't fudge it as something relative to another value.)

I'm guessing no because if there was something it'd be in Microsoft's stddef, but maybe there is something that just wouldn't also work on non-references?

This is not something I'm trying to do, so no need to answer with ARGH DON'T DO IT, I'm just curious whether it can be done, because of that library trying to do it.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
Not portably, no. The standard makes no promises about the storage of references.

MrMoo
Sep 14, 2000

roomforthetuna posted:

If you build boost on a 64-bit machine, using MSVC 9.0 (which is Visual C++ 2008), and you don't specify anything about address-model, will it default to building a 64-bit version or 32-bit?

Always 32-bit, as 64-bit is Professional+ versions only.

Paniolo
Oct 9, 2007

Heads will roll.

MrMoo posted:

Always 32-bit, as 64-bit is Professional+ versions only.

If you install the (free) Windows SDK you can target 64-bit platforms using the express editions of Visual C++.

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
I'm back with more circular dependencies/forward references/compiler just being nasty about my stuff. At this point I have a lot of source files referring to each other. What has ended up hurting me has been trying to break up particular classes into separate files. So I have stuff like:

1. class A in one file refers to class B in another file, and vice versa.
2. Add in class C with similar back-and-forth references classes A and B.
3. Add in some other classes that use classes A and B in different capacities.

At this point I'm dealing with the preprocessor not finding #include paths that are quite clearly there, at least at the location of the file in question. I have to assume these are getting dragged into a source at another path, and subsequently screwing up the compiler. Overall, I am wondering what I can do to mitigate this mess. The breakup of the files makes sense from a design and programming standpoint, but I have to figure out how to make the compiler happy.

The best I can come up to at this point is to put all the stuff in a big orgy into one common header that enforces at least some kind of order, and just let anything that needs to take advantage of the interplay of objects to include that file in particular. I just ask about that now because it'll take a lot of refactoring around and I'm not entirely sure I won't get out of the woods with it either.

baby puzzle
Jun 3, 2011

I'll Sequence your Storm.
There are some basic rules to getting that kind of thing working. When two or more classes must refer to each other, don't #include the other class's file into the header. Use forward declarations instead. You can #include whatever you need into the actual source files. Of course, forward declaration means that your class declaration can only refer to the forward declared class by address.

If I'm telling you what you already know, then you've ballsed up somewhere. Maybe you need to think about restructuring the whole thing.

Don't fall into making an uber-header just to get things working.

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
Edit: I am a moron who cannot point his slashes the right way. That was all there was too it. :lol: To be fair, I had thought I tried that first thing.

baby puzzle posted:

If I'm telling you what you already know, then you've ballsed up somewhere. Maybe you need to think about restructuring the whole thing.

Don't fall into making an uber-header just to get things working.
The case where I wound up posting to complain about it before came about from some restructuring. I've managed to solve all of my problems so far with forward declarations and such. I had a nice first round of problems when I had pulled a lot of stuff out of a growing header file into separate files. This second restructuring was where I started to put the sources in different directories and subdirectories. At that point, I'd get problems with it not being able to locate headers. I assume it's because one header in directory A is referring to a header in directory B. I haven't figured out which way it went in the rabbit hole; I'm using Eclipse to manage the project and I haven't yet dug through it to figure out in what order it's trying to compile crap.

I'm using relative paths for the source tree, so the #include is like "..\..\stuff.hpp" and I haven't figured out through exhaustion what might alternately make it happy. Maybe I'll try absolute path for giggles.

Sorry for all this ramblings but I'm kind of thinking out loud in the thread.

Rocko Bonaparte fucked around with this message at 17:15 on Aug 14, 2011

Brecht
Nov 7, 2009
I have a stream of input messages, each of which triggers a handful of sequential operations. It's easy enough to do procedurally, but because some of the operations block on IO, I'm hitting a performance wall which is killing my throughput. So I want to pipeline the work, and my first thought is to break it into distinct tasks for each shared resource, and call them asynchronously. Is boost async the best bet here? Should I be trying a completely different approach?

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Rocko Bonaparte posted:

I'm using relative paths for the source tree, so the #include is like "..\..\stuff.hpp" and I haven't figured out through exhaustion what might alternately make it happy. Maybe I'll try absolute path for giggles.
I believe the rule for relative paths is it's relative to the location of the file you're in, so if you have a structure like
code:
> project
| file1.h
|-> subdir
| | file2.h
| |-> subdir2
| | | file3.cpp
Then either file3.cpp contains
#include "../file2.h"
#include "../../file1.h"


Or file3.cpp does
#include "../file2.h"

and file2.h does
#include "../file1.h"


To simplify this sort of thing, another option is to add each of the paths to your preprocessor include paths, and use angle-bracket includes #include <file2.h> or (to avoid using complete paths) add just the "project" directory to your include paths, and #include <subdir/file2.h>

beuges
Jul 4, 2005
fluffy bunny butterfly broomstick
Also, MSVC is (thankfully) quite happy with parsing paths with forwardslashes instead of backslashes. So #include "../../blah.h" will work even when building on Windows.

TasteMyHouse
Dec 21, 2006
I'm actually not aware of anything in windows that DOES care about forward slashes vs. back slashes

Good Will Punting
Aug 30, 2009

And as the curtain falls
Just know you did it all except lift weights
So I'm learning about overloading operators and my professor posted this code sample:

code:
istream& operator>>(istream &in, const MyString &obj) {
char tmp[80];
in >> tmp;
obj = MyString(tmp); //this line here!
return in;
} // end operator>
I might be brainfarting, but can someone explain the nature of the commented line?

Dicky B
Mar 23, 2004

obj is assigned to a new instance of type MyString.

MyString(tmp) constructs a temporary object. obj is immediately assigned to this temporary object. Most likely a copy operation occurs, so now the two objects are equivalent (but not the same object). The temporary object on the right hand side of the expression then disappears from existence after the assignment.

TasteMyHouse
Dec 21, 2006
that also won't compile because obj is const.

nielsm
Jun 1, 2009



TasteMyHouse posted:

I'm actually not aware of anything in windows that DOES care about forward slashes vs. back slashes

I believe some of the lower levels in the kernel does, but if that applied to you you'd probably already know :)

That Turkey Story
Mar 30, 2003

TasteMyHouse posted:

that also won't compile because obj is const.

Maybe it has a const assignment operator :downs:

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

That Turkey Story posted:

Maybe it has a const assignment operator :downs:
That's what I thought when I read the code. The operator could either forcibly drop the const and be naughty, and do what's expected, or maybe it does something completely different, like how just yesterday I saw a "/=" operator being overridden to do some sort of string concatenation or something.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

nielsm posted:

I believe some of the lower levels in the kernel does, but if that applied to you you'd probably already know :)

Also the command shell does - just try running debug/something.exe.

Good Will Punting
Aug 30, 2009

And as the curtain falls
Just know you did it all except lift weights
Thanks for the help! I have two more questions! (and probably a lot over the next two weeks as I have a final coming up for this class, which is going to kick my rear end).

1.)
code:
NameRecord * aPtr;
aPtr = new NameRecord[numRecs];
int i;
for (i = 0; i < numRecs; i++)
in >> aPtr[i].first >> aPtr[i].last; 
Input is a list of first and last names, first and last are objects of another class. It's my understanding that in the last line, in will read the first name of the first record until a white space appears and the characters that are read will be input into aPtr[0].first (I think this is the idea?) However, I'm confused about how they are stored. When the NameRecord array is created, and the respective first and last objects are created for each NameRecord object, is the appropriate constructor (char pointer to an array of characters) called as the values are read in during that last line? (This seems like the reasonable process, but I just wanted to clear it up).

2.)
code:
if (sortBy == 1) {
if (first == ob.first)
return (last > other.last);
else
return (first > other.first);
} 
This snippet is part of an operator overloading function for the > operator. I don't understand how the objects are compared. "last" and "first" are objects of a class which contains a pointer pointing to a dynamic array of characters, but how does it know to compare that as opposed to other member variables of "last" and "first"? And how is a comparison like that even done?

Jesus Christ, typing this out and thinking about this class makes me feel so loving stupid. I've never struggled with a class like this. I seem to understand it when I read through everything but when I go back I am absolutely lost. It's the worst information overload I've ever experienced.

Good Will Punting fucked around with this message at 02:32 on Aug 15, 2011

Dicky B
Mar 23, 2004

1.) The default NameRecord constructor will be called "numRecs" times on line 2, once for each object in the array. The default constructor is a constructor with no parameters. If such a constructor isn't defined then it will be automatically generated by the compiler.

2.) Depends how operator > is implemented for the type of first and last.

Good Will Punting
Aug 30, 2009

And as the curtain falls
Just know you did it all except lift weights
Well both of those make sense and I now have a much better idea of what's going on. Thanks a lot for the speedy reply! I'd like to think brainfarts like this happen when you're first learning and spend 6 hours just reading about new concepts staring at code.

TasteMyHouse
Dec 21, 2006

Jabor posted:

Also the command shell does - just try running debug/something.exe.

Haha Windows owns:

Only registered members can see post attachments!

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

TasteMyHouse posted:

Haha Windows owns:
Frustrating inconsistency is the spice of life!

rikshot
Jan 8, 2006
Ran into a bug in VS2010. The following crashes the compiler when compiled in Release mode. It does compile fine without the static modifier. Found this somewhat interesting.

code:
#include <iostream>

int main() {
	static auto const test([](int unsigned const & a) -> double {
		return 1.0 / a;
	});
	
	std::cout << test(10) << '\n';

	return 0;
}
I guess that's kinda pushing it, considering the final spec just only just got approved.

brosmike
Jun 26, 2009

rikshot posted:

Ran into a bug in VS2010. The following crashes the compiler when compiled in Release mode.

I went to file a bug for this today but I couldn't reproduce it. Do you have SP1 installed? Do you have any non-default configuration settings in your Release configuration? Do you get any information beyond "it crashes" from the compiler?

rikshot
Jan 8, 2006

brosmike posted:

I went to file a bug for this today but I couldn't reproduce it. Do you have SP1 installed? Do you have any non-default configuration settings in your Release configuration? Do you get any information beyond "it crashes" from the compiler?
code:
1>------ Rebuild All started: Project: test, Configuration: Release Win32 ------
1>Build started 17.8.2011 22:48:44.
1>_PrepareForClean:
1>  Deleting file "Release\test.lastbuildstate".
1>InitializeBuildStatus:
1>  Touching "Release\test.unsuccessfulbuild".
1>ClCompile:
1>  main.cpp
1>main.cpp(6): fatal error C1001: An internal error has occurred in the compiler.
1>  (compiler file 'msc1.cpp', line 1420)
1>   To work around this problem, try simplifying or changing the program near the locations listed above.
1>  Please choose the Technical Support command on the Visual C++ 
1>   Help menu, or open the Technical Support help file for more information
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:02.00
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
There is the compiler output. There is some discussion about this when Googled. It seems that Microsoft knows about this issue, but doesn't consider it critical...

I have SP1 and all the latest updates etc. People seem to get this error with some other C++11 features as well. Can't wait to switch to LLVM & Clang.

elite_garbage_man
Apr 3, 2010
I THINK THAT "PRIMA DONNA" IS "PRE-MADONNA". I MAY BE ILLITERATE.
Is there a native way to add two entire arrays (same size) to each other instead of having to loop through the array's size and add each variable one at a time?

I'm looking for an easier way to do this:
code:
for (int i = 0; i < 1;) 
{
    x += n[i] + pos[i];
    ++i;
    y += n[i] + pos[i];
    cout << "Your current position is: " << x << " " << y << endl;						
}
I know the sum/display would need to be added to a new array instead of x or y. I'm just showing you guys what I'm using now.

elite_garbage_man fucked around with this message at 02:39 on Aug 19, 2011

shrughes
Oct 11, 2008

(call/cc call/cc)

elite_garbage_man posted:

I know the sum/display would need to be added to a new array instead of x or y. I'm just showing you guys what I'm using now.

How about you show what you actually want to do instead of something that is not that?

Edit: Also, no there's no native way. Unless the arrays are declared with a fixed size.

pseudorandom name
May 6, 2007

code:
#include <algorithm>
#include <iostream>
#include <array>

int main(int argc, char* argv[])
{
	using std::array;
	using std::transform;
	using std::cout;
	using std::endl;
	using std::plus;

	array<int, 2> a = { 0, 1 };
	array<int, 2> b = { 2, 3 };
	array<int, 2> out;

	transform(a.begin(), a.end(), b.begin(), out.begin(), plus<int>());

	cout << out[0] << " " << out[1] << endl;

	return 0;
}
The question is, of course, was that worth the effort?

Adbot
ADBOT LOVES YOU

elite_garbage_man
Apr 3, 2010
I THINK THAT "PRIMA DONNA" IS "PRE-MADONNA". I MAY BE ILLITERATE.
Thank you.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply