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
Qwertycoatl
Dec 31, 2008

Does VS still do that thing where if you use standard library string functions it tells you to use special Microsoft ones instead?

Adbot
ADBOT LOVES YOU

Bonfire Lit
Jul 9, 2008

If you're one of the sinners who caused this please unfriend me now.

Qwertycoatl posted:

Does VS still do that thing where if you use standard library string functions it tells you to use special Microsoft ones instead?

Yep. You can disable the warning though (it's C4996).

Hughlander
May 11, 2005

roomforthetuna posted:

The other thing VC++ does that's bad for cross-platforming is that it does everything with vcproj files where the more-standard is makefiles. That's pretty unhelpful when it comes to compiling on other systems.

(Not that you can't use the compiler with text editors and command lines and stuff, but if you use the IDE then you'll be using vcproj files.)

You can also tell it to output a .mak file as well. I have a solution that has several build targets some that use cl, some that use gcc, each time I hit build solution on the gcc one it generates a .mak file.

That Turkey Story
Mar 30, 2003

As much fun as it is to bash Microsoft, Visual Studio is a great IDE and the compiler is also very compliant (all compilers have issues, yes, even gcc, though clang is pretty awesome). People still have a sour taste in their mouth from VC++ 6, which was in development before the first C++ standard was even ratified in 1998 and it's gotten to the point that people don't even remember why they hate it anymore. True, VC++ still does have some non-compliant extensions, but for the most part, everyday compliant code will compile. Unless you are doing advanced stuff with templates or non-trivial stuff with the preprocessor, neither of which most people do, you generally won't have problems. Even there, VC++ can handle most modern template metaprograms without a hitch.

This is coming from someone who does lots of crazy template stuff -- VC++ is not a bad compiler and Visual Studio is a good IDE.

Also, as was pointed out, you can export makefiles.

Paniolo
Oct 9, 2007

Heads will roll.
It's pretty rare to run into non-standard stuff when using the Visual C++ compiler. The Visual C++ runtime is another matter, because it doesn't include stuff from C99 which you do get using libc on most other platforms. So you run into issues like needing to use _snprintf, etc. When it comes to C++ though, their standard library is very compliant.

And the IDE is the best IDE.

As far as cross-platform build systems I would look into CMake, which can generate both makefiles and Visual C++ project/solution files from your source CMakeLists.txt file. At work we use CMake to build projects that target about a dozen different platforms, and it's a godsend compared to what we used to do.

wellwhoopdedooo
Nov 23, 2007

Pound Trooper!

nielsm posted:

FYI, just using the Visual C++ IDE does not magically make your code become non-standard. There's two ways VC++ can make you write weird code: MFC and C++/CLR (C++ for .NET). With the Win8 Developer Preview there's also a third, C++/CX. But it's not like it writes weird code behind your back, unless you actually tell it to create a project using any of those variations.
Just get Visual C++ 2010 Express and start writing standard C++ using a good compiler and wonderful IDE.

(Actually, you don't even get MFC with VC Express, so that's one less.)

It just seems to me that people have some weird ideas about VC++ making you write terrible non-standard code... maybe that was true 10 years ago with version 6. That's 10 years ago.

Programs are like water and will naturally expand to fill their API container. If you're writing your code in Visual Studio (or anywhere, really, but Visual Studio stands out) and not taking specific steps to stay cross-platform/ANSI, you're deluding yourself if you think you're writing cross-platform/ANSI code.

That said, worry about writing portable C++ once you know how to write C++ in the first place, and Visual Studio has a really sweet help system.

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!

wellwhoopdedooo posted:

and Visual Studio has a really sweet help system.
I liked the help system from way back in 1998 when it was called "Developer Studio", when it used .hlp file behavior instead of compiled html. It meant generated indexes and searches that were both faster and more helpful than the newer help system - I could pretty much always type a single word and get exactly what I wanted out of it. The new one takes a while and then insists on trying to spew MFC and Visual Basic junk at me half the time (I don't even have VB or MFC stuff installed).

I guess the new help system is still good compared to the nothing that most other IDEs offer, but I really miss the help system that was borderline effortless. (I kept using that one past two major version iterations because the help system was just that much better.)

NOSTALGIA.

wellwhoopdedooo
Nov 23, 2007

Pound Trooper!

roomforthetuna posted:

I liked the help system from way back in 1998 when it was called "Developer Studio", when it used .hlp file behavior instead of compiled html. It meant generated indexes and searches that were both faster and more helpful than the newer help system - I could pretty much always type a single word and get exactly what I wanted out of it. The new one takes a while and then insists on trying to spew MFC and Visual Basic junk at me half the time (I don't even have VB or MFC stuff installed).

I guess the new help system is still good compared to the nothing that most other IDEs offer, but I really miss the help system that was borderline effortless. (I kept using that one past two major version iterations because the help system was just that much better.)

NOSTALGIA.

Oh, yeah, actually using the help system is a loving nightmare. But, it's really, really thorough, at least compared to anything else I've ever seen, and the examples (something most other documentation practically ignores) are invaluable to learning.

Paniolo
Oct 9, 2007

Heads will roll.
I'm really curious what kinds of help topics generate results for both MFC and Visual Basic.

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!

Paniolo posted:

I'm really curious what kinds of help topics generate results for both MFC and Visual Basic.
A number of Win32 function names will do it, because they share names with member functions of MFC classes and whatever it is VB has. Also if you forget the name of a function and try to find it by searching for what it does, that'll frequently net you wrong-language results (eg. "create a window")

I think the old help files had a lot of manual index entries, like a book written by actual human beings for human beings, so when you searched for stuff it would have a much better chance of taking you to the stuff you're looking for.

I'd still use the old Win32 SDK hlp file if I could, when working with Win32, but we're not even allowed to open hlp files any more, with modern Windows. :(

Paniolo
Oct 9, 2007

Heads will roll.
Oh, I understand now - you're hitting F1 for help? Yeah, that doesn't work at all. MS generally has excellent documentation but you're better off using Google to get to it. Alternately if you install the Windows SDK it comes with the kind of self-contained help file you're looking for, as does DirectX. Doesn't integrate into VS, though, at least I haven't been able to get it to.

Paniolo fucked around with this message at 02:29 on Sep 24, 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!

Paniolo posted:

Oh, I understand now - you're hitting F1 for help? Yeah, that doesn't work at all. MS generally has excellent documentation but you're better off using Google to get to it. Alternately if you install the Windows SDK it comes with the kind of self-contained help file you're looking for, as does DirectX. Doesn't integrate into VS, though, at least I haven't been able to get it to.
Not F1, but the help->search thing or help->index menu, which is what used to be good in the old version.

The new self-contained help files, as with DirectX's, are also what I'm grumbling about, because they are the compiled HTML format, which is the one where most of the 'search' stuff is auto-generated and thus dumb. (Though the auto-generated part of old help file indexes was better too! But it was twice as betterer for being combined with a human-influenced index.)

But yes, it's also true that if you want to use MSDN at all then only Google works. I found it pretty funny last time I tried it that Microsoft's own search engine didn't have the page I wanted in its entire first page of results, even though it was limited to searching only within MSDN, whereas Google had the page I wanted (from MSDN) as the second result from a dataset comprising everything on the web.

Edit: To be fair, the DirectX help file isn't actually too bad, it's certainly not nearly as sickening as the VC++ built in doc search. But it's also not nearly as amazingly helpful as the historical Win32 SDK help file.

roomforthetuna fucked around with this message at 04:11 on Sep 24, 2011

pseudorandom name
May 6, 2007

MSDN has the annoying habit of listing the Windows CE page first, instead of the actual result you want.

tractor fanatic
Sep 9, 2005

Pillbug
How come stream operators don't have covariant return types?

code:
string wee = (stringstream() << 5.5).str();
Won't compile since operator<< for stringstreams returns ostream&

nielsm
Jun 1, 2009



tractor fanatic posted:

How come stream operators don't have covariant return types?

code:
string wee = (stringstream() << 5.5).str();
Won't compile since operator<< for stringstreams returns ostream&

Virtual-ness is my guess.

If stringstream::operator<< was to return a stringstream& then it couldn't implement the ostream::operator<< which (for hopefully obvious reasons) must return ostream&. They also can't both exist at the same time because you can't overload on return type alone.

tractor fanatic
Sep 9, 2005

Pillbug
Wouldn't that just be a covariant return type? stringstream (I assume) derives from ostream so a function that returns stringstream& can override a function that returns ostream&.

shrughes
Oct 11, 2008

(call/cc call/cc)
I've seen it compile on some platforms and not compile on others.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
The deal is that operator<< is not necessarily specified directly on stringstream, so what you're actually asking for is a language feature that says the function returns the same type as its first argument. That's not actually reasonable to implement given multiple inheritance.

n.b. I haven't actually checked the library standard about this.

Plorkyeran
Mar 22, 2007

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

nielsm posted:

Virtual-ness is my guess.

If stringstream::operator<< was to return a stringstream& then it couldn't implement the ostream::operator<< which (for hopefully obvious reasons) must return ostream&. They also can't both exist at the same time because you can't overload on return type alone.
The stream operators aren't actually virtual. In fact, streams have zero virtuals other than the destructors - the virtual method dispatch occurs in basic_streambuf.

As usual, rjmccall is right about the stream operators not being specified directly on stringstream; they're defined in basic_istream and basic_ostream.

OneEightHundred
Feb 28, 2008

Soon, we will be unstoppable!
Platform-specific fun stuff: It looks like if you allocate memory using "new", then Visual C++'s debugger will break it down as the type it was allocated as even if referenced through a parent type or void pointer. However, if it was created using a custom allocator (i.e. placement new), it only shows as the type of the pointer you're looking at.

Anyone know if there's a mechanism for producing the type-aware behavior with a custom allocator?

OneEightHundred fucked around with this message at 21:34 on Sep 27, 2011

The1ManMoshPit
Apr 17, 2005

OneEightHundred posted:

Platform-specific fun stuff: It looks like if you allocate memory using "new", then Visual C++'s debugger will break it down as the type it was allocated as even if referenced through a parent type or void pointer. However, if it was created using a custom allocator (i.e. placement new), it only shows as the type of the pointer you're looking at.

Anyone know if there's a mechanism for producing the type-aware behavior with a custom allocator?

VS can only do this if your class has a v-table, because that's what it uses to determine the type at run-time. It should work no matter where the memory is or how it was allocated as long as it does.

Edit: I just threw together a quick test and verified this myself in VC++ Express 2010;

code:
class Parent
{
public:
    Parent(int i) : a(i) {}
    // comment out the virtual destructor and the runtime info isn't there in either case
    // leave it in and the info shows up in both cases
    virtual ~Parent() {}
private:
    int a;
};

class ChildOfParent : public Parent
{
public:
    ChildOfParent(int i, int j) : Parent(i), b(j) {}
private:
    int b;
};

void FunctionTakingParent(Parent* p)
{
    int i = 1 + 2;  // breakpoint here
}

int main(int argc, const char* argv[])
{
    char buffer[1024];
    Parent* pp = new (buffer) ChildOfParent(1, 2);
    Parent* pq = new ChildOfParent(1, 2);
    FunctionTakingParent(pp);
    FunctionTakingParent(pq);

    return 0;
}

The1ManMoshPit fucked around with this message at 02:45 on Sep 28, 2011

litghost
May 26, 2004
Builder

The1ManMoshPit posted:

VS can only do this if your class has a v-table, because that's what it uses to determine the type at run-time. It should work no matter where the memory is or how it was allocated as long as it does.

Shouldn't it also be able to do it if RTTI is enabled?

Paniolo
Oct 9, 2007

Heads will roll.

litghost posted:

Shouldn't it also be able to do it if RTTI is enabled?

RTTI only works for classes with a vtable.

litghost
May 26, 2004
Builder

Paniolo posted:

RTTI only works for classes with a vtable.

Didn't know that. It is interesting that GCC for example doesn't warn about this (using typeid on a type without a vtable).

pseudorandom name
May 6, 2007

Types without a vtable can only possibly be one type which is known at compile time.

Slanderer
May 6, 2007
I'm rewriting a module for a c/c++ project (most of the files are c, at least the ones I am in charge of), and the shortcomings in my education are taking their toll...

I had just written up a couple of paragraphs, but it was getting so convoluted that I scrapped it. I'm dealing with a preemptive real time operating system on an ARM processor, and I'm having concerns about concurrency issues between three different threads and an asynchronous interrupt routine that vomits data at one thread whenever it pleases. Does anyone have any good reading on this subject matter, whether online or in textbook form?

OneEightHundred
Feb 28, 2008

Soon, we will be unstoppable!

pseudorandom name posted:

Types without a vtable can only possibly be one type which is known at compile time.
I'm pretty sure this isn't true, you just wind up getting a vptr after the vptr-less parent class's properties.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

OneEightHundred posted:

I'm pretty sure this isn't true, you just wind up getting a vptr after the vptr-less parent class's properties.

Are you talking about adding virtual methods to a class when none of the base classes have vtables? I don't think that's what pseudorandom name is talking about, but anyway. All the major C++ ABIs will arrange class layout so that, if the class has any virtual method tables, one such table will appear at offset zero. Therefore, if you have a non-virtual base with no vtable, and you need a vtable, the base will always be allocated at a non-zero offset. Similarly, if your first declared non-virtual base has no vtable but your second non-virtual base does, the second base class will be at offset zero. This is true even in vfptr/vbptr ABIs like MSVC, although it gets a little more complicated.

Popete
Oct 6, 2009

This will make sure you don't suggest to the KDz
That he should grow greens instead of crushing on MCs

Grimey Drawer
Nevermind

Popete fucked around with this message at 06:00 on Sep 29, 2011

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
How well does Visual Studio .NET 2010 handle native C++ code these days? I heard you have to go through some hoops to make it poop out native code. I am developing on Linux with Eclipse, but I'm tempting the thought of transitioning, since I can get a license easily (and legit) enough. But I don't want to doodle around in it and find it's not particularly better. As an IDE, I'm trying to find something that does a better job calling me out on my bullshit before I spend a few minutes compiling. I am also hoping its build time is faster.

Speaking of build times, is it worth it perhaps to just so up the build environment on a ram disk or something? My computer is going on 5 years old and I'm thinking of upgrading, but meanwhile I have 8GB of RAM that I don't fully use when developing. I was thinking of making a 1GB ram disk. Is there something in Eclipse to encourage it to use that space for building and debug running? Is the copy transfer time worth it?

Slanderer posted:

I had just written up a couple of paragraphs, but it was getting so convoluted that I scrapped it. I'm dealing with a preemptive real time operating system on an ARM processor, and I'm having concerns about concurrency issues between three different threads and an asynchronous interrupt routine that vomits data at one thread whenever it pleases. Does anyone have any good reading on this subject matter, whether online or in textbook form?

If you've had some background with concurrency then I wouldn't bother looking up concurrency generally. Instead, go with the library documentation for whatever you are using. Look up how it handles locks in the documentation and how people are doing it online. Then similarly check how the documentation demonstrates waiting and notification, and similarly look online at how people do it. You'll probably find people bitching about something in the library and there might be a known issue or limitation.

Step back from the main work you're trying to do and just get some producer-consumer stuff working to your satisfaction. I used to think producer-consumer was particularly dry but it has represented most of the concurrency situations I've had. You're talking about three threads, so maybe it doesn't make sense in its simplest form but maybe it does whatever you're doing.

OneEightHundred
Feb 28, 2008

Soon, we will be unstoppable!

Rocko Bonaparte posted:

I heard you have to go through some hoops to make it poop out native code.
Not really, there's a setting which determines what kind of code it outputs (native, native+MSIL, MSIL-only, and some specializations of those) and that's pretty much it.

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:

Speaking of build times, is it worth it perhaps to just so up the build environment on a ram disk or something? My computer is going on 5 years old and I'm thinking of upgrading, but meanwhile I have 8GB of RAM that I don't fully use when developing. I was thinking of making a 1GB ram disk. Is there something in Eclipse to encourage it to use that space for building and debug running? Is the copy transfer time worth it?
I'd think you'd just set the intermediate build directories to a location on the ramdisk, and I guess also the final link directory for debug versions. What copy transfer time would there be? Are you thinking copying all the source files to the ramdisk too, or something?

I imagine debug building the object files to a ramdisk would be a worthwhile timesaving if you have that much spare RAM, but I doubt copying all the source files to a ramdisk would be (the pain in the rear end getting it set up right alone would offset any gains).

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
Putting intermediate files on a ram disk can make linking a lot faster, but compiling is usually CPU-bound.

gonadic io
Feb 16, 2011

>>=
I'm trying to teach myself C/C++ coming from Java, could somebody look over my implementation of a singly-linked list? I've tested it a little and it seems to work.
http://pastebin.com/WGhEiH0L

Some things I'd like to know are:
- are there errors/memory leaks I can't see?
- how is my style?
- this is in C++, how much harder would it be to do this in C (using calloc instead of new and so on)
- how would I store data of an arbitrary type? Void pointers?

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!

AlsoD posted:

- are there errors/memory leaks I can't see?
In your 'insertAt' function, if the list is empty it inserts the new item with an 'append' but then doesn't exit the function. You then go on to prepend it if the index given is zero, and again don't exit the function. End result of this is that if you called insertAt(0,value) on an empty list, you get three insertions of the same value. It looks like you were thinking those ifs would behave like everything else is in an "else" block, but didn't write it that way.

I'd also say that stylistically that function is a bit bad, in that it doesn't inform you if it fails to insert (index out of bounds), and if you call it on an empty list it adds the element regardless of what index you gave (ie. index out of bounds prevents insertion sometimes but not other times. Inconsistent function behavior is not good). The lazy fix for that would be to make it so any index out of bounds means you just append - that way you don't need to return errors, and it's not an entirely unreasonable behavior.

quote:

- this is in C++, how much harder would it be to do this in C (using calloc instead of new and so on)
Almost no difference.

quote:

- how would I store data of an arbitrary type? Void pointers?
Yes, if you want to do it C style. Templates, if you want to do it C++ style.

Edit: Also, I could be mistaken but it looks like your 'get' function has the return value backwards - if your decrementing index has not run out (reaching -1) then you have a valid pointer, but you have it returning 0 if it's not run out, and the pointer if it has run out. You don't even need to do that check, since your 'temp' pointer will be zero (the value of a null pointer) anyway if it reaches the end of the list. (Line 64.)

roomforthetuna fucked around with this message at 20:40 on Sep 29, 2011

OneEightHundred
Feb 28, 2008

Soon, we will be unstoppable!

Plorkyeran posted:

Putting intermediate files on a ram disk can make linking a lot faster, but compiling is usually CPU-bound.
Compiles are massively sped up by having more CPUs/cores.

Links can strain CPU/RAM as well if you're using link-time code generation.

TasteMyHouse
Dec 21, 2006

AlsoD posted:


//linked list
Why is everything public?

Jort
Jan 10, 2007
code:
class vector
{
    friend class matrix;
private:
    int length;
    double* contents;
public:
    vector();
    vector(int size);
    ~vector();
    vector(const vector &);
    double getComponent(int i);
    void setComponent(int i, double val);
    double dotProduct(vector *v2);
    void read(ifstream &stream);
    void print();
};





vector::vector()
{
    length=0;
    contents=0;
}


vector::vector(int size)
{
    assert(size > 0);
    length = size;
    contents = new double[length];
    assert(contents != 0);
    for(int i = 0; i< length; i++)
    {
        contents[i] = 0;
    }
}



vector::~vector()

{
    delete [] contents;
    length = 0;
}
The program runs correctly, multiplying vectors and matrices and printing the correct result, but it tells me "malloc: *** error for object 0x100100d50: pointer being freed was not allocated" after it completes and is attempting to close.

I can see that object in this memory spot is a a vector filled with my desired values, but for some reason the deconstructor is giving me problems. I've tried to make sure I'm using the correct syntax by researching online, and it seems as if I am. Any ideas on how to solve this?

Jort fucked around with this message at 19:25 on Sep 30, 2011

OneEightHundred
Feb 28, 2008

Soon, we will be unstoppable!
You might be copying the full object when doing something, in the process copying the contents pointer and causing a double-free when the destination dies.

Adbot
ADBOT LOVES YOU

Jort
Jan 10, 2007
Ok, so it looks like it's trying to free the "this" pointer. How would I go about dealing with this double creation? I'm using a copy constructor

code:

vector::vector(const vector & init)
{
    length = init.length;
    contents = new double[length];
    assert (contents != 0);
    for (int i = 0; i<length; i++)
    {
        contents[i] = init.contents[i];
    }
}
which may be the issue?

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