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
OddObserver
Apr 3, 2009
NestedObject &NestedObject::operator=(const NestedObject &other)
doesn't resize annotate.

Beyond that, use a memory debugger --- if you're on Linux or OS X, use Valgrind.
It's quite possible that the "unimportant stuff" you cut out is what's actually
screwing up.

Adbot
ADBOT LOVES YOU

OddObserver
Apr 3, 2009
operator=. And you have some temporaries there.

OddObserver
Apr 3, 2009
code:
Fl_Gl_Window
FL_Gl_Window
l != L

OddObserver
Apr 3, 2009
I hope the profile was at least done with a fully optimized build?

OddObserver
Apr 3, 2009
Hmm. well, there is whatever addr2line does, too, if you don't mind linking to libbfd (which may be acceptable for purely debug stuff..)

Does the compiler in question use the same C++ ABI as gcc, BTW? If it does,
abi::__cxa_demangle might be of some use.

OddObserver
Apr 3, 2009

Ledneh posted:

The compiler in question is Sun CC provided with Sun Studio 12.1. I don't really want to link anything that's going to murder production performance, either, though I want to be able to get the stack trace in production for the sake of more useful exception info.

Well, the issue is more that libbfd is GPL'd, which is quite likely to be an issue for production stuff.

Hmm. An another option: if you have good control over production binaries, it may be possible to do the line number processing off-line, though you'd need to extract the memory map to know which libraries are located where. Sounds like one of those sorta-simple but pretty fiddly kind of tasks (again, addr2line code may be a good starting point for the post-processing tool).

OddObserver
Apr 3, 2009
^^^^^
put your implementation in the header. It can't get instantiated from the .cpp

And on an unrelated note:

Ugg boots posted:

king_kilr posted:

If you treat money as a floating point, I will find you and hurt you.

This needs to be reiterated because it wasn't replied to.

To elaborate, I am pretty sure you can't accurately represent numbers as simple as 0.10 (e.g. 10 cents) in (binary) floating point.

OddObserver
Apr 3, 2009

Ledneh posted:

Another question on the Boehm-Demers-Weiser GC. Is there some magic incantation I have to perform to make datain STL containers traceable (if not collectable)? In my test code so far I'm getting objects deleted prematurely everywhere, seemingly becauseit isn't tracking pointers stored in STL maps.

IIRC, You need to get it to use GC_alloc for memory. Hopefully it provides an allocator...

OddObserver
Apr 3, 2009

Lord Flashheart posted:

Crossposted from the general programming questions thread:

Doing a project in which this c program needs to reconfigure it's radio. Unfortunately, the only interface is through http. Trying to write my own POST requests with information gleaned from a capture.

http://www.mediafire.com/?aljig4jboiur4p2
Here is the capture of my attempt. The first POST request I wrote works, however the second isn't even processed by Wireshark as http. I am not exactly sure why.

You're sending stuff after the server sent Connection: close. If it does that, you should (I think it actually is a SHOULD...) disconnect and open a new connection.

Edit: actually, it's stronger than that; it's a MUST NOT:

RFC 2616/8.1.2 posted:

Persistent connections provide a mechanism by which a client and a
server can signal the close of a TCP connection. This signaling takes
place using the Connection header field (section 14.10). Once a close
has been signaled, the client MUST NOT send any more requests on that
connection.

OddObserver fucked around with this message at 09:15 on Oct 12, 2010

OddObserver
Apr 3, 2009

Mopp posted:

Yes, I'm doing this according to instructions and were told to use pointers. Shouldn't the constructor still be called?


edit: or rather, calc.h has an "VariableTable* table" declared, but I was unsure how to proceed from there. How do I assign an VariableTable to T in an correct way then?

You never create the object. It's an uninitialized pointer pointing to some (sorta) random location (which may not even be) in memory.

OddObserver
Apr 3, 2009

DeciusMagnus posted:

This deletes the current b every iteration. Your way was deleting after the for loop was done, which means you were deleting null.

It also accesses the nextBlock field of the just deleted one.

OddObserver
Apr 3, 2009
Frequently impossible.

More specifically, it depends on whether they use the same C++ ABI (Application Binary Interface --- which specifies how function names are encoded and layout of things like objects and vtables). For a long time basically everyone's scheme was different --- even different gcc versions were incompatible. There are perhaps a few more compatibilities now: both g++ >= 3.2 and some other Unix-friendly compilers like Intel's use the same ABI that was cooperatively designed for Itanium, but there is still a lot more that's different than that's same.

(Also, I am not 100% sure of how the runtime library stuff is supposed to work when mixing compilers...)

It -seems- that Sun CC is incompatible, but luckily the difference appears to be huge --- you'll likely just get tons of link errors if you try.

Edit: if you want to know more about how an ABI looks, here is what g++ uses:
http://www.codesourcery.com/public/cxx-abi/abi.html

There is also of course an ABI for C that this builds on. Those are usually pretty much compatible since they're much simpler, but
sometimes problems still crop in with stuff like SSE and whatnot.

OddObserver fucked around with this message at 04:50 on Oct 23, 2010

OddObserver
Apr 3, 2009
If you're on Linux or OS X use valgrind's Massif tool.

Edit: and for non-initialized variables, its default Memcheck tool. It's also generally not true that debug builds do any special initialization
(though some debug version of malloc fill fresh memory with known patterns).

Edit #2: It might honestly be worth the effort to try building it under Linux to just run Valgrind. There is some chance it wouldn't be much work,
and if you don't have a Linux system it's easy enough to just use a LiveCD.

OddObserver fucked around with this message at 04:12 on Oct 24, 2010

OddObserver
Apr 3, 2009
Actually Xlib is pretty simple (and similar, to Win32, really) for most of the basic things, too --- creating windows, drawing things, etc (though it's somewhat complicated by having both modern and obsoleted ways of doing things). There are some things, however, that are indeed pretty complex --- basically anything that involves interaction between different clients, in particular clipboard and drag-and-drop, requires implementing protocols from some lower-level primitives, and can get pretty messy.

Oh, and X11/Xlib doesn't actually provide any actual widgets itself, which is sort of a big deal for actual applications (but not so much if you just want to play around and see the basics of how things work).

OddObserver
Apr 3, 2009

FlyingDodo posted:

Say I have a tree and I want to be able to get something from the tree by getting a pointer/reference to an object in it, not a copy. Is there a way to prevent the objects from being modified? I know I could use a const pointer or reference but its still possible to cast it as a plain old pointer and then change the data the pointer is pointing at. This is bad because the object would no longer make sense in the place it is in the tree.

Is there someway to prevent this?

As stated? No (modulo some crazy stuff like mprotect if the object is meant to be entirely readonly). But as an alternative, you could make use of a copy-on-write type to get a similar effect, though at cost of some refcount thrashing.

OddObserver
Apr 3, 2009
http://www.parashift.com/c++-faq-lite/templates.html#faq-35.18

OddObserver
Apr 3, 2009
You need to say
'typename MyClass<_Ty>::MyFooTest' when referring to such a type in templated contexts.

OddObserver
Apr 3, 2009
Add template<typename _T> before the void. Also you really want to pass in vectors by const reference; passing them by value is O(n).

OddObserver
Apr 3, 2009

roomforthetuna posted:

Not entirely a C++ question, but this seems like a good thread for it - is there a quick way to test the dynamic linking of a Linux "shared object" file, that I could use in a Makefile? As it is, if I accidentally try to use a function within the .so that the main program has available but the .so does not, the first I know of it is when I run the program and get:
"dlopen failed: ./whateverlibrary.so: undefined symbol: WHATEVERFUNCTION"

ldd -r seems to be that, though I am too lazy to actually try.

OddObserver
Apr 3, 2009
Pass a pointer (or a reference).

OddObserver
Apr 3, 2009

Rocko Bonaparte posted:

I have been compelled to write some Python wrappers for some code I've been using. This has been slow-going for awhile but I am slowly starting to wrap my head around the Boost Python wrappers. Where I am stuck is how I could wrap bit fields. I actually didn't even know about bit fields until just now. The Boost Python bindings work with references to the properties or functions being wrapped, but one cannot take a reference to a bit field according to what I know of C++.

Why not just add accessor functions and wrap those?

OddObserver
Apr 3, 2009

tractor fanatic posted:


I don't get this: why isn't concrete using abstract::test(int)? Why is it trying to use concrete::test(float) or concrete::test(double) instead?

I think abstract::test(int) gets hidden due to having overloads in a subclass.

OddObserver
Apr 3, 2009
Less educational but easier: just use popen() (and pclose()).

OddObserver
Apr 3, 2009
.. And it's principal and not principle.

OddObserver
Apr 3, 2009
Also, vec<float,3> a(); doesn't do what you think it does. It actually declares a function!

OddObserver
Apr 3, 2009

tractor fanatic posted:

I have a thread which checks if a bool is set, and if it is, calls a function through a pointer. Once set, neither the bool nor the pointer will change for the lifetime of the thread. Another thread will set the pointer and then set the bool. I don't care about the case where the pointer has been set but the bool is not. Are there any race conditions I haven't thought of, and is it a horror to just mark both the bool and the pointer as volatile, ignoring any other threading structures?

You need memory barriers --- otherwise the write to the pointer may become visible -after- the write to the bool in the reading thread.

OddObserver
Apr 3, 2009
Where does the null termination come from?

OddObserver
Apr 3, 2009
if you can use ssh, you may e able to use scp or sftp.

OddObserver
Apr 3, 2009
For a really nice POSIX reference, there is always the source, e.g.: http://pubs.opengroup.org/onlinepubs/007904975/functions/write.html

Sometimes it even has historical and rationale discussions...

OddObserver
Apr 3, 2009
If you are on an OS that supports it, valgrind. In that case, of course, you should be able to tweak build flags beyond Debug/release to get debug info in there.

Also, --gtest-filter will let you run a subset of tests

OddObserver
Apr 3, 2009
I think it's correct behavior, assuming this is C++, and not some typedef.
bool's are permitted to behave as neither true nor false if you don't use
them in a proper, well-defined, typesafe way (the standard gives an example of an uninitialized bool); and this is clearly doing weird stuff since there is nothing that says that true and false have to be represented in a certain way (in particular, sizeof(bool) need not be 1); merely that they convert to and from ints in a certain way.

OddObserver
Apr 3, 2009
That'd likely be because you're passing in a pointer to a local to the thread start function. Don't do that --- by the time the thread is running, the variable may already be out of scope, with its stack space used for something else (like the instance of FD of the next iteration).

OddObserver
Apr 3, 2009

Vanadium posted:

Fix the API. :colbert:

Well, that's one way to learn ;-) Sometimes -fpermissive helps a bit, though it's usually for stuff that's way older than 4.1.2.

OddObserver
Apr 3, 2009

Vanadium posted:

But cpp processes definitions and does the whole substitution thing, it doesn't output the definitions again. :(

gcc has -E -dM which prints defined macros out, see:
http://gcc.gnu.org/onlinedocs/gcc-4.7.2/gcc/Preprocessor-Options.html#index-dM-972


(Though I don't see the connection with bindings)

OddObserver
Apr 3, 2009
Oh, std::swap is now written in terms of std::move, isn't it?

OddObserver
Apr 3, 2009

Ciaphas posted:

I've got some questions about creating and linking libraries.

- C++'s name mangling means any library compiled by, say, g++ 4.6 is only going to be linkable with other programs compiled using g++ 4.6, correct? Or is it less stringent than that?

4.7 and 4.8 will work as well (at least as long as you don't turn on C++11 mode, not sure of the current state of that). Basically all recent g++ versions are compatible (modulo bugs)
but might require a libstdc++ at least as new as the version you've compiled against to run.

quote:

- What about libraries compiled in C? Discounting target processor, is use of them still restricted to the compiler they were made with?

Basically generally inter-operable unless you hit weird spots, and again, you might run into trouble if you run against an older glibc version than you built against.

Edit: also, the real advantage of dynamic libraries is when tons of apps use the same library --- you get to share most of the code/data memory for it between different processes, which is nice.

OddObserver fucked around with this message at 05:16 on May 2, 2013

OddObserver
Apr 3, 2009
I wonder why they didn't just make "only public POD data" (aka compatible with a C struct) a special case?

OddObserver
Apr 3, 2009

GrumpyDoctor posted:

Does changing it to vec.end() shut Coverity up?

Surely they're the same for an empty vector, considering what a standard
loop over range looks like?

OddObserver
Apr 3, 2009

Suspicious Dish posted:

It's not like strlcpy is any less broken. What should you use instead?

Well, the conversation that inspired it probably calls for strdup anyway.

Adbot
ADBOT LOVES YOU

OddObserver
Apr 3, 2009

Mr. Crow posted:

I'm learning gtest and c++ and can't wrap my head around how to do this, any guidance?

Lets say I have a templated class

code:
template<typename T>
class ItemBase : public OtherBase
{
public:
    T getFoo();
}
with multiple implementations. I want to test the logic in ItemBase<T> using type-parameterized tests so all implementors can test the shared logic. I've got it working fine with OtherBase because the parent is not templated; I'm having trouble getting my head wrapped around how to do this with the templated ItemBase<T> class. Help?


The primary issue I guess, is that I need to somehow have a member variable in my test fixture that's the concrete ItemBase<U>* type so I can reference it in it's tests, with the U being the pain in the rear end I can't figure out. It seems like only a single template parameter is allowed for classes deriving from ::testing::Test?

I am not sure I really understand your question, but TYPED_TEST and TYPED_TEST_CASE may be of use.
https://code.google.com/p/googletest/wiki/AdvancedGuide#Typed_Tests
(Or alternatively TYPED_TEST_P)

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