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
RonniePudding
Oct 18, 2005

[SOLVED]

Using Visual Studio 2008, how can I output a DLL for both 32bit and 64bit systems? "Any Key" doesn't appear in the MSVS help files either which is what I read I have to use.

*EDIT I found the "Platform" option in my project settings, but it is set to Win32 and that is the only option. So I have a DLL that is set to Win32 and works on a 64bit machine and not a 32bit machine. This doesn't make sense!

*EDIT2 Installed C++ redistributable on 32bit test machine and it now works.

RonniePudding fucked around with this message at 19:17 on May 26, 2010

Adbot
ADBOT LOVES YOU

slovach
Oct 6, 2005
Lennie Fuckin' Briscoe
I realized that something like:
code:
static unsigned int f[10] = { 0, 1, 1 };
will actually fill it with 0 1 1 0 0 0 0 0 0 0. Is this something I can rely on?

Crazy RRRussian
Mar 5, 2010

by Fistgrrl
Perhaps this is a wrong thread to ask for this, but can somebody recommend me good books and/or online materials for learning MPI from scratch? Also feel free to share your experience in learning and using it.

UraniumAnchor
May 21, 2006

Not a walrus.

slovach posted:

I realized that something like:
code:
static unsigned int f[10] = { 0, 1, 1 };
will actually fill it with 0 1 1 0 0 0 0 0 0 0. Is this something I can rely on?

I believe statics/globals get filled with default/zero already, but for local variables you can rely on the above, yes.

Mustach
Mar 2, 2003

In this long line, there's been some real strange genes. You've got 'em all, with some extras thrown in.
Yes. Here's how you zero-initialize an array: int a[N] = {};. The same principle holds for initializing C-style strings. (Stop using memset for that, my precious coworkers)

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

slovach posted:

I realized that something like:
code:
static unsigned int f[10] = { 0, 1, 1 };
will actually fill it with 0 1 1 0 0 0 0 0 0 0. Is this something I can rely on?

Yes, for two reasons:

1. Everything with static storage duration (i.e. variables with global scope, static local variables, and static data members) is guaranteed to be zero-initialized at program start even if not otherwise initialized. So you could write
code:
static unsigned int f[10];
and it would be zero-initialized.

2. When an aggregate (i.e. a struct or array) is initialized with an initializer list, missing members are value-initialized (which is the same as zero-initialized for ints).

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

Mustach posted:

Yes. Here's how you zero-initialize an array: int a[N] = {};. The same principle holds for initializing C-style strings. (Stop using memset for that, my precious coworkers)

Note that you need at least one value in your initializer list for C.

Mustach
Mar 2, 2003

In this long line, there's been some real strange genes. You've got 'em all, with some extras thrown in.
Dang, that was a perfect opportunity for you to use :viggo:.

ToxicFrog
Apr 26, 2008


LockeNess Monster posted:

Perhaps this is a wrong thread to ask for this, but can somebody recommend me good books and/or online materials for learning MPI from scratch? Also feel free to share your experience in learning and using it.

I've not used MPI directly; I found it much easier to use Pilot on top of it. If you're doing low level wizardry this won't be useful to you, but for general use, it provides a much smaller and cleaner interface and semantics than using raw MPI does. Basically, it's a semisynchronous message passing library with runtime deadlock detection implemented on top of MPI.

There are also Fortran, Python, and Lua bindings for it in varying levels of maturity, if that's what turns your crank.

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

ToxicFrog posted:

I've not used MPI directly; I found it much easier to use Pilot on top of it. If you're doing low level wizardry this won't be useful to you, but for general use, it provides a much smaller and cleaner interface and semantics than using raw MPI does. Basically, it's a semisynchronous message passing library with runtime deadlock detection implemented on top of MPI.

There are also Fortran, Python, and Lua bindings for it in varying levels of maturity, if that's what turns your crank.
I'm not sure I agree. MPI is a sufficiently high level library that I don't think you need yet another layer to make it comprehensible - it does a pretty good job of hiding the scary stuff while giving you sufficient control over your parallelization, while still has the collective scatter/gather/generic reduction routines that your link does, too.

For the person asking the question: I've used this one and it's pretty good.

RonniePudding
Oct 18, 2005

I have a large array that I need to divide into 4 smaller arrays.

buffer -----------> ( buffer_1 , buffer_2 , buffer_3 , buffer_4 )

The only way I know how to do this is iterating to each value, which is really slow:

code:
for(int i=0,i<1000000,i++,){
buffer[i] = buffer_1[i]
//etc...
}
1.) Is there a faster way?
2.) Are there any boost functions that could help with this?
3.) Should I use a vector rather than an array?


*EDIT
It's also important that the array retains the original order

RonniePudding fucked around with this message at 01:24 on May 28, 2010

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
code:
buffer_1 = buffer + offset_1;
buffer_2 = buffer + offset_2;
...

RonniePudding
Oct 18, 2005

Whoa so that will shift the starting address by the offset? If so I love you and I mean it.

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

of course, AD's approach doesn't make a copy of the array since it's just doing pointer arithmetic. If you expect the original array to be modified elsewhere, or if you want to split the array several times into distinct copies which themselves will be changed, you'll have no choice but to copy the array.

edit: if you have to copy the array, at the very least use something like memcpy.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
It will, but be careful about memory management. You need to free/delete buffer (or equivalently buffer_1 if its offset is 0), not the others.

Dijkstracula posted:

edit: if you have to copy the array, at the very least use something like memcpy.

Don't do this if you have an array of non-POD types (i.e. most anything except primitive types and "C-style" structs).

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

Avenging Dentist posted:

Don't do this if you have an array of non-POD types (i.e. most anything except primitive types and "C-style" structs).
Ah, yeah, good point - really, if you have a datatype that requires a deep copy, don't listen to me. :)

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

Avenging Dentist posted:

Don't do this if you have an array of non-POD types (i.e. most anything except primitive types and "C-style" structs).

0x will get a little more lenient with what it considers a POD type but I'm too lazy to :google: a description of the changes

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

Otto Skorzeny posted:

0x will get a little more lenient with what it considers a POD type but I'm too lazy to :google: a description of the changes

Inheritance is legit if only one class in the inheritance hierarchy has non-static members (this means CRTP can be used with PODs :woop:). Also you can have non-default constructors now by explicitly setting the default constructor to the trivial case: constructor() = default;. There's some other stuff, but it doesn't really matter.

RonniePudding
Oct 18, 2005

Dijkstracula posted:

of course, AD's approach doesn't make a copy of the array since it's just doing pointer arithmetic. If you expect the original array to be modified elsewhere, or if you want to split the array several times into distinct copies which themselves will be changed, you'll have no choice but to copy the array.

edit: if you have to copy the array, at the very least use something like memcpy.

I'm using a memmove() right after a memcmp() so this solution is perfect.

Before I was doing:
code:
				convert[0] = false;
				for(int i = RANGE_1_START ; i < RANGE_1_END ; i++)
				{
					if(buffer_old[i] != buffer_new[i])
					{
						buffer_1[i] = buffer_new[i];
						convert[0] = true;
						num++;
					} else { num++; }
and now I'm doing:

code:
				if(memcmp(buffer_1,buffer_new,RANGE_SIZE)!=0)
				{
					memmove(buffer_1,buffer_new,RANGE_SIZE);
					convert[0] = true;
				} else { convert[0] = false; }
Would buy from again!! A++++++

RonniePudding fucked around with this message at 03:29 on May 28, 2010

_aaron
Jul 24, 2007
The underscore is silent.
I've got a .Net COM server, and I want to pass an object to that server from a C++ client. I've got no problem creating the COM server object on the C++ end. My server object (.Net) has a method that looks like this:

public void RegisterCallback(object callback)

And this method is visible to me in my C++ client. I've got an object in C++ that just defines a simple method that returns an int (just for testing/proof-of-concept purposes).
code:
class CppClient
{
private:
    int myInt;

public:
    int myNumber() {
        return myInt;
    }

    CppClient(int num) {
	myInt = num;
    }    
};
What I'd like to do is create an instance of CppClient and pass that instance to the RegisterCallback() method on the .Net COM object. This is giving me all kinds of headaches.

When I call the RegisterCallback() method in my C++ code, passing in an instance of CppClient, it's trying to marshal that object as a bool, which obviously isn't working. I probably have to do some more COM-related stuff with CppClient, but I'm just not sure what that "stuff" is. Can anyone help point me in the right direction?

Thanks.

edit: finally got this figured out. If anyone cares about the solution, I'd be happy to post it.

_aaron fucked around with this message at 20:33 on May 28, 2010

UberJumper
May 20, 2007
woop

_aaron posted:

I've got a .Net COM server, and I want to pass an object to that server from a C++ client. I've got no problem creating the COM server object on the C++ end. My server object (.Net) has a method that looks like this:

public void RegisterCallback(object callback)

And this method is visible to me in my C++ client. I've got an object in C++ that just defines a simple method that returns an int (just for testing/proof-of-concept purposes).
code:
class CppClient
{
private:
    int myInt;

public:
    int myNumber() {
        return myInt;
    }

    CppClient(int num) {
	myInt = num;
    }    
};
What I'd like to do is create an instance of CppClient and pass that instance to the RegisterCallback() method on the .Net COM object. This is giving me all kinds of headaches.

When I call the RegisterCallback() method in my C++ code, passing in an instance of CppClient, it's trying to marshal that object as a bool, which obviously isn't working. I probably have to do some more COM-related stuff with CppClient, but I'm just not sure what that "stuff" is. Can anyone help point me in the right direction?

Thanks.

edit: finally got this figured out. If anyone cares about the solution, I'd be happy to post it.

Can you? Awhile back at my past job i spent awhile trying to figure out the best way to do that (i never did COM before). I ended up coming up with a horrific solution so i would love to see how to better do it.

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
http://article.gmane.org/gmane.comp.gcc.devel/114407 :laugh:

ChiralCondensate
Nov 13, 2007

what is that man doing to his colour palette?
Grimey Drawer
Saw this post, thought it was in the coding horrors thread...

Vanadium
Jan 8, 2005

Clearly if they just switch to C++ (that is, saying class instead of struct and maaaaaybe using member functions), they will catch up to clang in no time!

That Turkey Story
Mar 30, 2003

Vanadium posted:

Clearly if they just switch to C++ (that is, saying class instead of struct and maaaaaybe using member functions), they will catch up to clang in no time!

Eh, they're talking about using constructors and destructors and STL which really is a big improvement. No templates is still a sad sight, though.

Either way, there's no way they'll catch up if the Clang train passes them by, which in some ways it already has.

Pivo
Aug 20, 2004


fixd

Pivo fucked around with this message at 23:24 on May 31, 2010

HauntedRobot
Jun 22, 2002

an excellent mod
a simple map to my heart
now give me tilt shift

They're really arguing about which type of coal to fuel the steam engine there.

OddObserver
Apr 3, 2009

Vanadium posted:

Clearly if they just switch to C++ (that is, saying class instead of struct and maaaaaybe using member functions), they will catch up to clang in no time!

Well, at least more of them might notice just how slow compiling C++ code is with gcc.

clearly not a horse
May 8, 2009

undue butt brutality is not a criminal offense
I am having a small transition from Python to learn some new stuff and I have a simple question, but first I have to explain my problem.

In Python I made a class called "node" which I used to simulate a hierarchical structure. It had several attributes like name, depth, parent and children among others. My question regards the list of children which contained objects, or references to other instances of the class node.

How can I simulate this in C++? Can I create an array/list in my object which can contain references/pointers to other object? Below is a brave attempt to explain what I mean in some C++-like pseudocode.

code:
class node {

protected:
    SomeType children [Arbitrary number of objects/pointers/whatever];

    void addChild (SomeType child) {
        //Some way to put the parameter into the array/list "children".
    }

};

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
C/C++ arrays are necessarily fixed-length, so if you want to story an arbitrary number of children in an array, you'll need a data structure which can resize that array. The STL provides a generic resizable-array data structure called std::vector, so if you wanted a vector of pointers to nodes, you'd have something like:

code:
class node {
protected:
 std::vector<node*> children;

  void addChild(node *n) {
    children.push_back(n);
  }
};
You can't make arrays of references; if you need the layer of indirection, which it looks like you do, then it has to be pointers.

clearly not a horse
May 8, 2009

undue butt brutality is not a criminal offense
Thanks for the reply, but I am running into some problems.
I have no understanding of vectors so I am not able to analyze the code.
The compiler tells me that I cannot declate a vetor with no type. I am guessing the compiler does not read "Node" as a type, but I may be horribly wrong.
I would appreciate any elaboration or some advice as to how to do what I want.

code:
class Node {

protected:
	string name;
	vector<Node*> children;
	
	void addChild (Node *n) {
		children.push_back(n);
	}
	
	void get () {
		for (i = 0; i < children.size(); i++) {
			cout << children.at(i).name;
		}
	}
	
public:
	Node (string tname) {
		name = tname;
	}
};

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
Works fine over here: http://codepad.org/u4vlf9K9

(Your code is broken because 1) you aren't declaring i, and 2) you're trying to use a pointer like a value type).

Volguus
Mar 3, 2009
Here is some sample code: http://codepad.org/TOTixB1a
Same code is pasted here if you don't want to click:
code:
struct ShapeInterface
{
 virtual void Draw()=0;
 virtual void SetName(char* name)=0;
 virtual char* GetName()=0;
};
struct CircleInterface:public ShapeInterface
{
  virtual void SetRadius(double radius)=0;  
};
class ShapeImpl:public ShapeInterface
{
  virtual void SetName(char* name){/*save it somewhere*/}
  virtual char* GetName(){/*return it*/ return NULL;}
};
class CircleImpl:public CircleInterface,public ShapeImpl
{
 virtual void Draw(){/*draw a circle*/}
 virtual void SetRadius(double radius){/*set the radius*/}
};

int main()
{
 CircleImpl circle;
 return 0;
}
As it can be seen, the code tries to define 2 interfaces, and 2 implementations of those interfaces.
CircleInterface extends ShapeInterface, and CircleImpl extends ShapeImpl (while also implementing CircleInterface).
The error that the compiler throws is: cannot declare variable 'circle' to be of abstract type 'CircleImpl'.

My problem is with the 2 SetName/GetName methods. They are defined in ShapeInterface, and implemented in ShapeImpl.
However, it seems like I have to implement them in CircleImpl as well (even if they are just calling ShapeImpl::SetName()/ShapeImpl::GetName()).

Am I doing something wrong, or this is the way it's supposed to happen in C++.
Coming from Java, this construct (extend A implement B) is perfectly valid and I do not have to implement any methods that A defines that are implemented in B.

Can it be done in C++ too? Or will I just have to live with it?

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
Use virtual inheritance: http://codepad.org/Q21fhVP1

Volguus
Mar 3, 2009

Avenging Dentist posted:

Use virtual inheritance: http://codepad.org/Q21fhVP1

Thank you sir.

Le0
Mar 18, 2009

Rotten investigator!
Simple question,

I have a file1.cpp which includes file1.h with a struct and a class defined in there. The class uses a struct defined in file2.h.
file2.cpp includes file2.h, file2.h also includes file1.h because a class defined in file2.h uses the struct defined in file1.h.

If I do this I get an error, how should this type of stuff be done correctly?

Ari
Jun 18, 2002

Ask me about who Jewish girls should not marry!

Le0 posted:

Simple question,

I have a file1.cpp which includes file1.h with a struct and a class defined in there. The class uses a struct defined in file2.h.
file2.cpp includes file2.h, file2.h also includes file1.h because a class defined in file2.h uses the struct defined in file1.h.

If I do this I get an error, how should this type of stuff be done correctly?

Can you reproduce this in a couple of small stripped-down files and post the source and the error?

newsomnuke
Feb 25, 2007

It's almost certainly a cyclic dependency, you need to forward declare one of the classes.

(file1.h)
code:
#pragma once
#include "file2.h"

struct foo : public bar {};
(file2.h)
code:
#pragma once

struct bar {};

struct foo; // forward declaration for baz

struct baz : public foo {};
Then #include file1.h in file2.cpp

_aaron
Jul 24, 2007
The underscore is silent.

UberJumper posted:

Can you? Awhile back at my past job i spent awhile trying to figure out the best way to do that (i never did COM before). I ended up coming up with a horrific solution so i would love to see how to better do it.
Sorry this took me so long.

Basically, what we did was define an interface in our C# server app (call it IClient) and made this interface COM visible. We also changed the Register method on the server object to take in an IClient rather than an object.

After building our .tlb file, we can set up the C++ client. The client application needs to implement a class that implements the IClient interface. Part of exposing that interface to COM means that on the C++ end, IClient inherits from IDispatch (msdn), which in turn inherits from IUnknown (msdn) (both of which should be somewhat familiar if you struggled with COM for any amount of time ;))

We were mainly just doing this as a proof of concept (showing that our C# server could work with a C++ client), so our implementation of IDispatch is almost certainly wrong. But it worked for our purposes, and with a little tweaking could probably be made correct.

Here's the code for the C++ implementation of the interface. If there's anything else you'd like to see, let me know. If you've got a specific question, I can try to explain a little better, but like I said, this was just a proof of concept, and I'm really not sure that I understand it all that well myself. Good luck :)

Adbot
ADBOT LOVES YOU

digibawb
Dec 15, 2004
got moo?

ultra-inquisitor posted:

It's almost certainly a cyclic dependency, you need to forward declare one of the classes.

(file1.h)
code:
#pragma once
#include "file2.h"

struct foo : public bar {};
(file2.h)
code:
#pragma once

struct bar {};

struct foo; // forward declaration for baz

struct baz : public foo {};
Then #include file1.h in file2.cpp

You can't forward declare a type you are using as a base.

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