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
astr0man
Feb 21, 2007

hollyeo deuroga

Tusen Takk posted:

Good catch on that :v: I thought I had used the carot not the asterisk for some reason.

For future reference, there is a pow() function in math.h. But for something this simple there is no reason to include it and you should just stick with r * r.

Adbot
ADBOT LOVES YOU

mobby_6kl
Aug 9, 2009

by Fluffdaddy

That Turkey Story posted:

It all still stinks. Sorry, I don't actually have a recommendation, I just felt the need to say that.

I dunno, CreateWindow() works fine for me :smug:

Gul Banana
Nov 28, 2003

tractor fanatic posted:

How do people do GUI Windows programming in C++ nowadays? Is there a favored framework, or is it a mix of MFC, ATL, QT, etc?

if it's for windows just use .net wpf instead. even if you've literally never used .net before you'd still come out ahead on time and effort.

happykirwan
Jun 26, 2009
I am relatively new to C programming and I am having a small issue.

I am programming an embedded application on a microcontroller. The program is reading a line off of a SD card and storing it in memory as a string. This "string" is an ascii repesentation of a hex number. For example, the file on the sd card has just "12345678". I am trying to convert this string from its current form into a long int which the computer will read as a 32 bit hexadecimal number (as 0x12345678).

I feel as though I am missing something really basic. I have tried using atol (which just converts it as if it is an int in base 10, as opposed to base 16). The certain microcontroller I am using is lacking in library support, so I think I will have to do this manually.

Any ideas?

astr0man
Feb 21, 2007

hollyeo deuroga
Do you have strtol() available? It works the same way as atoi and takes a base argument.

edit: If you have atol I would think that you also have strtol, since on a lot of platforms atol just calls strtol with base 10.

Posting Principle
Dec 10, 2011

by Ralp

Gul Banana posted:

if it's for windows just use .net wpf instead. even if you've literally never used .net before you'd still come out ahead on time and effort.

This is the best option. Even if you have existing c++ that you need to use you can just p/invoke it easily enough.

If youre dead set on c++ or you have to be cross platform, Qt is the best option.

happykirwan
Jun 26, 2009
It turns out that I do!

And it worked brilliantly. Thanks.

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip

Also, you may want to czech out the embedded thread :)

Volte
Oct 4, 2004

woosh woosh

tractor fanatic posted:

How do people do GUI Windows programming in C++ nowadays? Is there a favored framework, or is it a mix of MFC, ATL, QT, etc?
I've been using Qt for a project and I really like it, but you have to pretend you aren't really programming in C++ (and in some respects you aren't, since Qt has a preprocessor that extends the language slightly). You pretty much have to embrace the entire Qt ecosystem, including their STL replacement classes. I recommend against using Qt Creator for coding though, which kind of sucks. If you're using Qt4 it's really easy to get CMake set up to do the build process for you (it's supposedly even easier in Qt5 but I couldn't get it to work) so you can use an editor of your choice. For something less invasive there's wxWidgets but I've never used it extensively. Qt has everything and the kitchen sink though and it's very easily extensible. The new version of Qt has a new C++-less framework called Qt Quick which is a similar idea to WPF but is based on a Javascript derivative called QML.

Contrary to what others have said I would not recommend using WPF with .NET. WPF is a great idea but I've found its execution to be extremely bad and I hope you like writing XML. Granted I haven't used it extensively in about five years but the problems were fairly deeply rooted in the overall design. XAML is incredibly verbose, and lacks the ability to inline code (you can embed code literally but it's not useful or recommended) so you end up with a lot of indirection in your interface design, like having to define Converters and Commands all over the place to do the two most fundamental tasks in WPF, bind data and react to events. The time you save in having a declarative interface definition language might well be lost in the development overhead introduced by that language being god awful in almost every respect.

I've never used QML and don't know if it's actually good but take a look at this example (from Wikipedia) and think about how much it would take to do it in WPF:
code:
Rectangle {
    function calculateMyHeight() {
        return Math.max(otherItem.height, thirdItem.height);
    }
    anchors.centerIn: parent
    width: Math.min(otherItem.width, 10)
    height: calculateMyHeight()
    color: { if (width > 10) "blue"; else "red" }
 }

Boz0r
Sep 7, 2006
The Rocketship in action.
I'm supposed to use SIMD and SSE to to optimize runtime of a raytrace renderer. I can't seem to find much info on how to use this in Visual Studio. Does anyone have any good resources for this?

Volguus
Mar 3, 2009

Boz0r posted:

I'm supposed to use SIMD and SSE to to optimize runtime of a raytrace renderer. I can't seem to find much info on how to use this in Visual Studio. Does anyone have any good resources for this?

Are you referring to this http://en.wikipedia.org/wiki/Streaming_SIMD_Extensions ?
Because these are just ... instructions. You can write them by hand or use a library. Maybe this would be helpful: http://stackoverflow.com/questions/61341/is-there-a-way-to-insert-assembly-code-into-c

tractor fanatic
Sep 9, 2005

Pillbug

Boz0r posted:

I'm supposed to use SIMD and SSE to to optimize runtime of a raytrace renderer. I can't seem to find much info on how to use this in Visual Studio. Does anyone have any good resources for this?

http://msdn.microsoft.com/en-us/library/y0dh78ez(v=vs.80).aspx

Volte posted:

You pretty much have to embrace the entire Qt ecosystem, including their STL replacement classes.

Is this a big deal in practice? Can I just use Boost and STL classes and convert only when I need to for Qt or is it a hassle?

tractor fanatic fucked around with this message at 00:12 on Feb 6, 2013

Xerophyte
Mar 17, 2008

This space intentionally left blank

Boz0r posted:

I'm supposed to use SIMD and SSE to to optimize runtime of a raytrace renderer. I can't seem to find much info on how to use this in Visual Studio. Does anyone have any good resources for this?

On a more abstract level than the syntax of it all, Ingo Wald's phd thesis spends quite a lot of time on ways to adapt ray/path tracer operations for SIMD. Admittedly it's a few years old now but the thing is surprisingly general for thesis work and should be a good place to start if you're not sure exactly what to do with the instructions when you have them.

awesmoe
Nov 30, 2005

Pillbug

tractor fanatic posted:

Is this a big deal in practice? Can I just use Boost and STL classes and convert only when I need to for Qt or is it a hassle?
It's a hassle but its definitely doable. The way we do it is use qt classes by default and convert them to std:: equivalents as we need them, or just use qt classes in stl containers. It's mostly qstring that's both ubiquitous and a pain in the rear end (although admittedly I miss the features when I don't have em).

we're still on qt 3.3 though :shobon:

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip

Boz0r posted:

I'm supposed to use SIMD and SSE to to optimize runtime of a raytrace renderer. I can't seem to find much info on how to use this in Visual Studio. Does anyone have any good resources for this?

The MSDN documentation for SSE intrinsics was pretty good last time I did anything with them, which was about a year and a half ago.

Rothon
Jan 4, 2012
If this is for an assignment you may not be able to use it, but ISPC allows you to write SPMD stuff without needing to deal with intrinsics manually.

Plorkyeran
Mar 22, 2007

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

tractor fanatic posted:

Is this a big deal in practice? Can I just use Boost and STL classes and convert only when I need to for Qt or is it a hassle?
Depends on how well the UI is segregated from the rest of the code. If you have nice well designed and testable code where the GUI is just a thin wrapper around a library, then it's a minor hassle. If not, it can quickly turn into a giant pain.

Boz0r
Sep 7, 2006
The Rocketship in action.
I'll have a look at that SIMD, thanks. In the meantime, I've made the renderer both with signed volumes and cramer's rule ray-triangle interception. On my Windows machine, a specific scene takes 96s to render with volumes and 110s with cramer's rule(I haven't optimized much yet). My friend's implementation runs on Linux, looks almost identical to mine, but his takes less than 20s to render the same scene. How can this be?

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip

Boz0r posted:

I'll have a look at that SIMD, thanks. In the meantime, I've made the renderer both with signed volumes and cramer's rule ray-triangle interception. On my Windows machine, a specific scene takes 96s to render with volumes and 110s with cramer's rule(I haven't optimized much yet). My friend's implementation runs on Linux, looks almost identical to mine, but his takes less than 20s to render the same scene. How can this be?

Are the specs on your computer and your friend's significantly different, are you using the same compiler and settings, etc? Notably, gcc will aggressively try to vectorize loops at high optimization levels


edit: cf. http://www.linux-kongress.org/2009/slides/compiler_survey_felix_von_leitner.pdf

Boz0r
Sep 7, 2006
The Rocketship in action.
I think he's using GCC and I'm using Visual Studio 2010. My CPU is significantly faster than his, though I don't know exactly what he has. I've got an i5-3570K.

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip
Assuming single-precision arithmetic, your ideal speedup from vectorization via SSE is 4x, with ~3.5x achievable in practice on problems where vectorization is a good fit. Given his code runs >5x faster than yours on slower hardware, that can't be the only thing. Without reading your code, there's not much I can say besides see what the profiler says. Nb. that an easy way to slow this sort of code down, vectorized or not, without even trying is by accessing memory in a way that sabotages your cache.

Boz0r
Sep 7, 2006
The Rocketship in action.
He tried using my code, and achieved a rendering time of 8.54 seconds on a i5 M520. I don't understand this. Mine is 109 seconds.

nielsm
Jun 1, 2009



Boz0r posted:

He tried using my code, and achieved a rendering time of 8.54 seconds on a i5 M520. I don't understand this. Mine is 109 seconds.

What are your compiler settings? If you're building using "debug" settings it's common to get factor 5 slowdowns or worse.

Xerophyte
Mar 17, 2008

This space intentionally left blank

Boz0r posted:

I'll have a look at that SIMD, thanks. In the meantime, I've made the renderer both with signed volumes and cramer's rule ray-triangle interception.

As noted, you're probably compiling in debug and/or attaching the VS debugger. Also, make sure your project is set to compile using fp:fast so it does floating point transforms for you. Setting in Project Properties > Configuration Properties > C/C++ > Code Generation. It can make a very large difference for this sort of stuff.

Also, intersection tests is one of those things where you almost definitely do not want to roll your own. There's a lot of previous work around. For ray-triangle and SIMD-optimization specifically, look at this one. Comes with code full of delectable SSE4 intrinsics and all that jazz.

FAT32 SHAMER
Aug 16, 2012



Boz0r posted:

I think he's using GCC and I'm using Visual Studio 2010. My CPU is significantly faster than his, though I don't know exactly what he has. I've got an i5-3570K.

My mate used VS10 on his code and I used GCC on mine and mine was a shitload faster/had less issues than his, too. I tried running my code in VS10 and I had a few issues, he used GCC and had less problems.

I honestly hate VS10 and prefer GCC but don't take my word as law since I'm very :shobon: with coding still.

Boz0r
Sep 7, 2006
The Rocketship in action.
My problem was the debug mode. Compiling in release mode nets me a render time of 5 seconds. I'm not that used to C++ yet, so every time I have to write something, I have to dick around in VS to make it not do all sorts of crazy poo poo.

Ciaphas
Nov 20, 2005

> BEWARE, COWARD :ovr:


If a class member function either explicitly calls a function override from one of its children, or even instantiates one of its child classes, is that the total faux pas I think it is? I've got some code from a project I'm trying to reuse for another project, but it does like the following code (where the child object references other modules that I really don't want to have to port over oh my god):

C++ code:
class Bar;

class Foo
{
public:
   void doStuff()
   {
      Bar b;
      // ...
      Bar::fart();
      // ...
   }
   virtual void fart() {}
};

class Bar: public Foo
{
public:
   virtual void fart() {}
// ...
};

Ciaphas fucked around with this message at 21:42 on Feb 7, 2013

shrughes
Oct 11, 2008

(call/cc call/cc)

Ciaphas posted:

If a class member function either explicitly calls a function override from one of its children, or even instantiates one of its child classes, is that the total faux pas I think it is?

No. Having a virtual method with children that exist just to override that virtual method is a common trick.

As for constructing the child temporarily in the parent goes, your code example won't actually compile (you'll have to put the doStuff implementation out-of-line, underneath the class Bar definition, and then it'll work), but as for the question of whether it's good software design, that depends on the situation. There do exist situations where strongly-coupled base classes and subclasses are needed. The "visitor pattern" is another situation in which you get equally strong coupling (the base class, with its visit method taking a particular visitor type, is directly tied to its set of subclasses).

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!

Ciaphas posted:

If a class member function either explicitly calls a function override from one of its children, or even instantiates one of its child classes, is that the total faux pas I think it is?
No, no more than having a class that instantiates more of itself, which is also fine. So long as the function definitions that do stuff with the child class are not in the header files.

shrughes
Oct 11, 2008

(call/cc call/cc)
By the way, I'm never sure what words to use. What is a "definition," "declaration," and "implementation" (and "prototype"?) when it comes to things like class foo;, class foo { };, /* inside class foo */ int method() const;, /* inside class foo */ int method() const { return 5; }, and int foo::method() const { return 5; }?

Ciaphas
Nov 20, 2005

> BEWARE, COWARD :ovr:


Okay, thanks for the info. Not sure how I'm gonna port this thing over now, though--I didn't write the thing so I've got to spend a few hours/days looking it over more closely. Wish I could just post the real code here and seek advice :smith:

shrughes posted:

As for constructing the child temporarily in the parent goes, your code example won't actually compile (you'll have to put the doStuff implementation out-of-line, underneath the class Bar definition, and then it'll work)

derp :doh:

Shugojin
Sep 6, 2007

THE TAIL THAT BURNS TWICE AS BRIGHT...


My general experience over the past week or so of near non-stop computational coding across gcc and VS on different studios says that gcc is vastly more cooperative with respect to computational stuff.

Bonfire Lit
Jul 9, 2008

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

shrughes posted:

By the way, I'm never sure what words to use. What is a "definition," "declaration," and "implementation" (and "prototype"?) when it comes to things like
class foo; and /* inside class foo */ int method() const; are declarations, class foo { };, /* inside class foo */ int method() const { return 5; } and int foo::method() const { return 5; } are definitions, int foo::method() const is a prototype. Roughly: if it includes a body, then it's a definition, otherwise it's a declaration.

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!
And I just looked up "prototype", it's basically the same thing as a function declaration, only explicitly "it contains all the parameters". Since nobody declares functions without all the parameters these days, there is no practical difference, other than people are more likely to know what you're talking about if you say declaration.

Edit: possibly a prototype might also refer to the thing you would use with a typedef, that resembles a declaration but isn't one because there's no actual function?

roomforthetuna fucked around with this message at 00:55 on Feb 8, 2013

That Turkey Story
Mar 30, 2003

shrughes posted:

By the way, I'm never sure what words to use. What is a "definition," "declaration," and "implementation" (and "prototype"?) when it comes to things like class foo;, class foo { };, /* inside class foo */ int method() const;, /* inside class foo */ int method() const { return 5; }, and int foo::method() const { return 5; }?

Definitions are declarations but not all declarations are definitions. I believe the standard always refers to class foo { /**/ }; as a class declaration, but most people always call that a class definition just to disambiguate it from a forward declaration of a class, myself included. The other thing that's sort of ambiguous is a template instantiation -- in the standard they are just called specializations, I believe, but people usually just say instantiation to differentiate it from explicit specializations and partial specializations. This is from memory and I don't feel like checking the standard, so I might be incorrect on how exactly it refers to things.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
You've got it down cold. In the standard, "instantiation" is the process of deriving a definition for a template specialization by substituting into the definition of a template, of a partial specialization, or of a member thereof (possibly recursively). Outside of the standard, "specialization" generally means an explicit specialization or partial specialization, and people use "instantiation" for basically anything that's either got template arguments itself or is nested inside something that does.

Tres Burritos
Sep 3, 2009

Okay this is bugging the poo poo out of me.

I've been playing with the Video 4 Linux API. So I query the devices capabilities and I look at this value "__u32 capabilities" That's an unsigned int, right?

I get the value 67108865 back. Which is 4000001 in hex. Okay. That makes sense according to the documentation. So I figure I can look at those properties and simply go

code:
if(capabilities & 0x00080000 == 0x00080000) cout<<"why the gently caress does a webcam have a RF emitter?"<<endl;
I'm doing something wrong here because every hex value I try like that is returning true. I feel stupid as poo poo that I'm somehow loving this up.

astr0man
Feb 21, 2007

hollyeo deuroga

Tres Burritos posted:

I'm doing something wrong here because every hex value I try like that is returning true. I feel stupid as poo poo that I'm somehow loving this up.

The == takes precedence over the bitwise and. So what that is really checking is
code:
if (capabilities & 1)
You want
code:
if ((capabilities & 0x00080000) == 0x00080000)
    cout<<"why the gently caress does a webcam have a RF emitter?"<<endl;
http://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B#Operator_precedence
Also, you don't actually need the == 0x80000, since it's only checking 1 bit. You could just do
code:
if (capabilities & 0x00080000)
    cout<<"why the gently caress does a webcam have a RF emitter?"<<endl;

Tres Burritos
Sep 3, 2009

astr0man posted:

The == takes precedence over the bitwise and. So what that is really checking is
code:
if (capabilities & 1)
You want
code:
if ((capabilities & 0x00080000) == 0x00080000)
    cout<<"why the gently caress does a webcam have a RF emitter?"<<endl;
http://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B#Operator_precedence
Also, you don't actually need the == 0x80000, since it's only checking 1 bit. You could just do
code:
if (capabilities & 0x00080000)
    cout<<"why the gently caress does a webcam have a RF emitter?"<<endl;

Oh goddamnit, thanks.

Adbot
ADBOT LOVES YOU

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
My VS2012 project always wants to build some stuff even if the files haven't changed. Online, I found this often has to do with files that have become missing, and I can find them if I turn on some debug logging. I did that and got a good look at 762 missing files in one of the projects. The big thing is that it's pointing to old crap off of a D:\ path that I used to use. I moved everything over to a C:\ path a few months back. The project itself builds fine; the project configuration inside Visual Studio looks right. I can't find any references to D:\ under the source tree. What the hell could it be? Is this some stupid precompiled header shenanigans?

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