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
User0015
Nov 24, 2007

Please don't talk about your sexuality unless it serves the ~narrative~!
Part of the trouble was that I already had a project started and moved my files over to MSVC midway through. MSVC helpfully used the source directory to dump it's files into after that. I guess it's output directory is shared by the input directory as default, or something.

Know any good write ups on property files I could browse? That might be a solid solution, depending how much it lets me control where and how MSVC looks for files and outputs content. Part of the reason it was giving me a headache was that it was attempting to link old files from the wrong directory after correctly building newer files, and since I just started using MSVC, I didn't know how to tell it to stop doing that. That's all solved now, but as I said, it's still dumping into wrong folders and generally placing files and folders where I don't want them to be.

Adbot
ADBOT LOVES YOU

nielsm
Jun 1, 2009



Along with the Solution Explorer tab in the (default) left pane, there is also a Property Manager tab. There you can create/add property files and edit them. You can stack multiple property files, and use different stacks for each project configuration. Do note that property files have a Save button of their own, in the Property Manager pane!
The basics are quite simple and I think it took me around 30 minutes to catch on to.

One of the useful features is also that you can define custom macros, you can use in other property values.

Some kind of overview
Custom macros
MSBuild (for hand-editing project and property files, to add more complex logic than the IDE lets you configure)

Farrok
May 29, 2006

Does anyone have any recommendations for a C graphing library? I'm considering DISLIN, Plotutils, or even embedding Python's matplotlib. What I really would like is functionality similar to MATLAB's quiver function in order to plot vector fields, so embedding Python might be the easiest route...however, I'm worried it will be slow, and it would be better if I could redraw the vector field in real time as various parameters change.

User0015
Nov 24, 2007

Please don't talk about your sexuality unless it serves the ~narrative~!
Thanks for the links. I'll have time later this week to take a look at them. Maybe I'll check out their full range of options more in-depth later on.

Safe and Secure!
Jun 14, 2008

OFFICIAL SA THREAD RUINER
SPRING 2013
I've been programming casually in Java for the past 4-5 years now, with a some extra classes as a CS student in the past year. I basically have zero C/C++ experience, though, which is something I'd like to change. I've got a copy of The C Programming Language, and the OP recommends The C++ Programming Language, but I see really good things about C++ Primer Plus on Amazon.

Is anyone here familiar with all of these books? C++PP just seems like such a huge book compared to The C Programming Language, but The C++ Programming Language isn't any better in that regard. Is C++ just an incredibly "large" language or what?

Safe and Secure! fucked around with this message at 07:41 on Dec 8, 2010

that awful man
Feb 18, 2007

YOSPOS, bitch

Safe and Secure! posted:

Is C++ just an incredibly "large" language or what?

C++ = C + exceptions + Simula-style objects + multiple inheritance + parametric polymorphism + ....

Scaevolus
Apr 16, 2007

Safe and Secure! posted:

Is anyone here familiar with all of these books? C++PP just seems like such a huge book compared to The C Programming Language, but The C++ Programming Language isn't any better in that regard. Is C++ just an incredibly "large" language or what?
Yes, C++ is an incredibly "large" language.

Accelerated C++ is another commonly suggested introductory book, followed by Effective C++.

Amarkov
Jun 21, 2010

that awful man posted:

C++ = C + exceptions + Simula-style objects + multiple inheritance + parametric polymorphism + ....

+ another Turing-complete language (hi templates!)

O_Kafetzis
Feb 15, 2010

by Nyc_Tattoo
I am trying to write a program in Mac OSX that looks at the metadata that is inside a binary. I found an API nlist() that seems to fit my needs.

The code I have is at http://codepad.org/EUQRdHYg

The problem I have is that at the linker stage I am getting this error
code:
$gcc nlist.c
Undefined symbols:
  "_nlist", referenced from:
      _main in cc3NtjkN.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
$
I have tried to wrap the include to the nlist.h file in extern "C" { ..} as suggested by http://www.saurik.com/id/3 but that does not solve my problem. As best, I can determine nlist() is in the libSystem and I think that gcc is finding that library.

Does anyone have any ideas on what I am doing wrong?

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

Pug1233 posted:

I am trying to write a program in Mac OSX that looks at the metadata that is inside a binary. I found an API nlist() that seems to fit my needs.

I asked our CC tools guy, and the consensus seems to be that you should not be using nlist, and that it's probably a bug that the manpage still exists.

You don't need to use extern "C", though, the header already does that.

What are you actually trying to do?

rjmccall fucked around with this message at 21:13 on Dec 9, 2010

slacjs
Feb 27, 2009

e: posted full code.

A pretty simple question I think but I can't figure out if I'm doing anything wrong.

I'm trying to create a method for the ExpTree class that returns a pointer to an object of type node and its input is a pointer to an iterator.

cpp file:
code:
#include "StdAfx.h"
#include "ExpTree.h"

#include <sstream>
#include <string>
#include <iterator>
#include <list>
#include <iostream>

template<class TE>
ExpTree<TE>::ExpTree(void)
{
	rootNode = NULL;
}

template<class TE>
ExpTree<TE>::~ExpTree(void)
{
	//
}

template<class TE>
void ExpTree<TE>::build(const TE & element)
{
	//String stream of expression.
	istringstream ss(element);

	//Tokenize into list.
	string mn;
	while(ss >> mn)
		listString.push_back(mn);
	
	//Create list iterator.
	list<string>::iterator it = listString.begin();
}

template<class TE>
Node* ExpTree<TE>::subBuild(std::list<std::string>::iterator* it)
{	
}
header file:
code:
#ifndef ExpTree_h
#define ExpTree_h
#include <list>

template <class TE>
class ExpTree
{
public:
	class Node;
	friend Node;
	
	//Class represents a node within an ExpTree.
	class Node
	{
	public:
		//Constructor
		Node(Node * leftptr, const TE &elem, Node * rightptr)
		{
			left	= leftptr;
			right	= rightptr;
			element = elem;
		};
		
		Node *left;		//Pointer to left child.
		Node *right;	//Pointer to right child.
		TE element;		//Element at node.
	};

	ExpTree(void);			//Standard Constructor.
	~ExpTree(void);			//Standard Deconstructor.
	void build(const TE &);	//Builds the expression tree.

private:
	Node* rootNode;										//Pointer to root node.
	Node* subBuild(std::list<std::string>::iterator *);	//Sub-method of build().
	std::list<std::string> listString;					//List of strings.
};

#endif
Visual studio doesn't like this. Anyone know what the problem is?

Errors:
code:
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 38
error C2065: 'TE' : undeclared identifier 38
error C2143: syntax error : missing ';' before '*' 38
These pop up twice with an error saying my object name is undeclared even though it's declared a line above.


slacjs fucked around with this message at 22:17 on Dec 9, 2010

O_Kafetzis
Feb 15, 2010

by Nyc_Tattoo

rjmccall posted:

I asked our CC tools guy, and the consensus seems to be that you should not be using nlist, and that it's probably a bug that the manpage still exists.

You don't need to use extern "C", though, the header already does that.

What are you actually trying to do?
Well I need to be able to determine if there is any debug information in an iPhone binary that will give hints on what functions were compiled as Thumb (or ARM). When looking at the nlist.h file, there is a constant called N_ARM_THUMB_DEF and I wanted to confirm that the constant was used before I went to the next step.

Vanadium
Jan 8, 2005

Fragaroc posted:

A pretty simple question I think but I can't figure out if I'm doing anything wrong.

I'm trying to create a method for the ExpTree class that returns a pointer to an object of type node and its input is a reference to an iterator.

cpp file:
code:
template<class TE>
Node* ExpTree<TE>::subBuild(std::list<std::string>::iterator* & it)
{	
}
header file:
code:
Node* subBuild(std::list<std::string>::iterator* &);
Visual studio doesn't like this. Anyone know what the problem is?

If I reconstruct a trivial program with those lines, it works in gcc, so I think you will need to post the error you are getting or maybe more code. :(

Plorkyeran
Mar 22, 2007

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

Fragaroc posted:

A pretty simple question I think but I can't figure out if I'm doing anything wrong.

I'm trying to create a method for the ExpTree class that returns a pointer to an object of type node and its input is a reference to an iterator.
code:
Node* subBuild(std::list<std::string>::iterator* &);
That function takes a reference to a pointer to an iterator.

slacjs
Feb 27, 2009

Vanadium posted:

If I reconstruct a trivial program with those lines, it works in gcc, so I think you will need to post the error you are getting or maybe more code. :(
Thanks for having a look, I've posted the rest of the code in the original post.

Plorkyeran posted:

That function takes a reference to a pointer to an iterator.
That was a mistake on my part, I've made it just a pointer to an iterator now though problems still occur. I would guess it is something to do with the definition of returning a Node* or something to do with the template, but I don't know for certain.

Thanks again.

slacjs fucked around with this message at 22:21 on Dec 9, 2010

pr0metheus
Dec 5, 2010
I took That Turkey Story's advise and here is my second iteration of SharedPtr class:

code:
#pragma once

template <class T>
class SharedPtr
{
	private:
		T * ptr;
		unsigned int * counter;
	public:
		/**
		 * Default constructor.  
		 */ 
		SharedPtr()
		{
			ptr = counter = 0;
		}

		/**
		 * Create a new reference counted shared pointer.  
		 */
		explicit SharedPtr( T * a )
		{
			this->ptr = a;
			counter = new unsigned int(1);
		}

		SharedPtr( const SharedPtr<T> & other )
		{
			ptr = other.ptr;
			counter = other.counter;
			(*counter)++;
		}

		~SharedPtr()
		{
			if( counter == 0 ) 
				return;
			(*counter)--;
			if( *counter == 0 )
			{
				delete ptr;
				delete counter;
			}
		}

		void operator = (const SharedPtr & other )
		{
			this->ptr = other.ptr;
			this->counter = other.counter;
			(*counter)++;
		}

		bool operator == ( const SharedPtr & other ) const
		{
			return other.ptr == this->ptr;
		}

		T & operator*() const
		{
			return *ptr;
		}

		T * operator->() const
		{
			return ptr;
		}

};
I don't quite understand why -> operator works by just returning *. Can somebody explain semantics of it and why returning the pointer works?

pr0metheus fucked around with this message at 22:40 on Dec 9, 2010

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

Pug1233 posted:

Well I need to be able to determine if there is any debug information in an iPhone binary that will give hints on what functions were compiled as Thumb (or ARM). When looking at the nlist.h file, there is a constant called N_ARM_THUMB_DEF and I wanted to confirm that the constant was used before I went to the next step.

Oh, there's a much easier way to test for that. The processor has to know whether a function is compiled for Thumb so that it can switch modes if necessary, so the function pointer encodes whether the function is ARM or Thumb in its low bit.

code:
if (((intptr_t) &someFunctionPointer) & 1) { // it's thumb! }

nielsm
Jun 1, 2009



pr0metheus posted:

I took That Turkey Story's advise and here is my second iteration of SharedPtr class:

I don't quite understand why -> operator works by just returning *. Can somebody explain semantics of it and why returning the pointer works?

Careful about that operator =, you're forgetting to unref the previous pointer, leaking ref counts.

As for operator ->, I'm pretty sure it's just supposed to return the pointer that the object wraps and the compiler then handles all the fancy stuff. You'd need a lot of crazy RTTI if the operator should be able to completely customise the look-up on the right-hand side of the ->. (I think that's what you're getting at.)

Vanadium
Jan 8, 2005

Fragaroc posted:

Thanks for having a look, I've posted the rest of the code in the original post.

Since Node is a type inside ExpTree<TE>, you need to define the function as:

template<class TE>
typename ExpTree<TE>::Node* ExpTree<TE>::subBuild(std::list<std::string>::iterator* it)
{
...

Plorkyeran
Mar 22, 2007

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

pr0metheus posted:

code:
void operator = (const SharedPtr & other )
{
    this->ptr = other.ptr;
    this->counter = other.counter;
    (*counter)++;
}
Think about what happens here when &other == this. This is one of the reasons why I generally prefer the copy-swap method for handling operator=.

Also, operator= should always return a reference to this so that chaining works.

pr0metheus posted:

I don't quite understand why -> operator works by just returning *. Can somebody explain semantics of it and why returning the pointer works?
operator-> simply returns a thing to use -> on instead (either a pointer or another object with overloaded ->); it doesn't completely replace the default functionality like most of the operators do. In practice this is enough for any sane usage of overloading ->, and it's the only remotely practical way to actually implement it.

Plorkyeran fucked around with this message at 23:25 on Dec 9, 2010

O_Kafetzis
Feb 15, 2010

by Nyc_Tattoo

rjmccall posted:

Oh, there's a much easier way to test for that. The processor has to know whether a function is compiled for Thumb so that it can switch modes if necessary, so the function pointer encodes whether the function is ARM or Thumb in its low bit.

code:
if (((intptr_t) &someFunctionPointer) & 1) { // it's thumb! }
While that is true if you have a function pointer to a function, as the compiler will add one to the true address of the function, but I am concerned with all functions and not just ones that have function pointers.

I can get a list of all addresses of the functions in a given program and those addresses will always be even (as confirmed by IDA) and will always be divisible by 2 but it may also be divisible by 4, which is why I need a better way then using the address.

Hughlander
May 11, 2005

Is there a set of win32 API calls that can open a .CAB file like a filesystem/directory as you would in windows explorer? I'd like to write a function that acts as findfirst/findnext but does so with a .CAB file as a file path rather than a system path. Oddly enough I'm having a hard time googling for the proper APIs that interact with Cabinet.DLL.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
http://msdn.microsoft.com/en-us/library/bb432569.aspx is the documentation for the cabinet API. Getting a list of files in the cabinet appears to be fairly awkward: the extract all function (FDICopy) takes a callback which receives information about each file before it's extracted and can tell the extractor to skip extracting the file.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

Pug1233 posted:

While that is true if you have a function pointer to a function, as the compiler will add one to the true address of the function, but I am concerned with all functions and not just ones that have function pointers.

It's a lot more than just the compiler, but yes, if you need to know this for a blob of code that you can't take the address of then you'll need something else.

Anyway, I *think* nlist will only fetch for the current architecture slice, and we don't offer an nlist for x86-64 or ARM. The debugger folks suggest using either libbfd or lldb, or alternatively there's an offset to the stabs in the MachO load commands.

Pug1233 posted:

I can get a list of all addresses of the functions in a given program and those addresses will always be even (as confirmed by IDA) and will always be divisible by 2 but it may also be divisible by 4, which is why I need a better way then using the address.

Yes, trying to infer thumbness from the 4-byte parity of the raw address will clearly not work for many reasons.

slovach
Oct 6, 2005
Lennie Fuckin' Briscoe
How can I fill an _m128 vector with 0x7FFFFFFF other than doing something retarded like:

code:
_m128 v;
v.m128_u32[0] = 0x7FFFFFFF;
v = _mm_shuffle_ps(v, v, 0x00);
I want to do an absolute value.
_mm_set1_ps(0x7FFFFFFF); ends up as 0x4F000000

digibawb
Dec 15, 2004
got moo?
Sounds like you are looking for _mm_set1_epi32, that's just a compound operation as well, similar to your initial code. _ps is just for floats.

EDIT: Though it may still be a better implementation...

digibawb fucked around with this message at 13:37 on Dec 10, 2010

slovach
Oct 6, 2005
Lennie Fuckin' Briscoe

digibawb posted:

Sounds like you are looking for _mm_set1_epi32, that's just a compound operation as well, similar to your initial code. _ps is just for floats.

EDIT: Though it may still be a better implementation...

I found a neat way this morning:

code:
_mm_set1_ps(-0.0f);
_mm_andnot_ps
edit: oops typo

slovach fucked around with this message at 22:37 on Dec 10, 2010

digibawb
Dec 15, 2004
got moo?
I missed the fact that your ultimate goal was to perform a fabs, sorry.

You could also look at:

_mm_max_ps( _mm_sub_ps( _mm_setzero_ps(), xyz ), xyz );

as that doesn't require any loads at all, but it depends how your register congestion is I guess!

EDIT: I've been stuck in PPC land for a while, so I'm a bit fuzzy on SSE and its general bottlenecks though, but it might help :)

slovach
Oct 6, 2005
Lennie Fuckin' Briscoe

digibawb posted:

I missed the fact that your ultimate goal was to perform a fabs, sorry.

You could also look at:

_mm_max_ps( _mm_sub_ps( _mm_setzero_ps(), xyz ), xyz );

as that doesn't require any loads at all, but it depends how your register congestion is I guess!

EDIT: I've been stuck in PPC land for a while, so I'm a bit fuzzy on SSE and its general bottlenecks though, but it might help :)

I'm barely using any registers.

I was playing around to see if I could beat fsincos. In 3 multiplies and an addition I have both a sine and cosine with pretty sketchy precision. 2 more and another abs and precision is much closer.

Haven't got around to actually profiling it yet but was a fun experiment nevertheless

wlokos
Nov 12, 2007

...
I'm trying to typecast a char as an integer, while said char is in a string. It is not working. Here is the code snippet in question:

code:
for(i=0; i<cipher; i++)
{
    if(isalpha(argv[1][i]) == 0)
    return 2;
    else
    key[i] = 'argv[1][i]';
}
Basically, I'm trying to make a Vigenere cipher (http://en.wikipedia.org/wiki/Vigenere_cipher). The user inputs their keyword to encrypt with in the command line, and this snippet checks that keyword (argv[1]) by making sure each letter is actually a letter (argv[1][i]). If successful, it's supposed to put that char in key[i], so that Key becomes an array of the values that the keyword implies... but it's not working. Instead, I get an error: "character constant too long for its type". I don't know what that means - it's an int, it should be able to hold the numerical value of a char, so I don't know.. Can anybody shed light on this for me?

Zhentar
Sep 28, 2003

Brilliant Master Genius
The text "argv[1][i]" contains 10 characters, which is too large to be assigned to a const char.

csammis
Aug 26, 2003

Mental Institution

wlokos posted:

I'm trying to typecast a char as an integer, while said char is in a string. It is not working. Here is the code snippet in question:

code:
for(i=0; i<cipher; i++)
{
    if(isalpha(argv[1][i]) == 0)
    return 2;
    else
    key[i] = 'argv[1][i]';
}
Basically, I'm trying to make a Vigenere cipher (http://en.wikipedia.org/wiki/Vigenere_cipher). The user inputs their keyword to encrypt with in the command line, and this snippet checks that keyword (argv[1]) by making sure each letter is actually a letter (argv[1][i]). If successful, it's supposed to put that char in key[i], so that Key becomes an array of the values that the keyword implies... but it's not working. Instead, I get an error: "character constant too long for its type". I don't know what that means - it's an int, it should be able to hold the numerical value of a char, so I don't know.. Can anybody shed light on this for me?

You're not typecasting argv[1][i] there, you're wrapping it in apostrophes. This means nothing to the compiler and it's telling you that the the phrase "argv[1][i]" is not a single character (which it obviously is not). A C-style typecast from int to char looks like this:

int i = (char)argv[1][i];

But that is completely pointless anyway because argv is a char**, which means argv[1][i] is already a char.

wlokos
Nov 12, 2007

...
Right, I'm trying to turn the char argv[1][i] into an int. Would that look like
code:
int key[i] = (int)argv[1][i];
?

I thought wrapping it in apostrophes made it an int because I did things like
code:
if(message[i]>='a')
and it worked in the past, which I think I got from an example somewhere. But clearly I'm misunderstanding something about that.

mr_jim
Oct 30, 2006

OUT OF THE DARK

'a' is a character literal, which in C is the same as the ASCII value 97.

code:
char c = 'a';
char c = 97;
These two lines are equivalent.

Vanadium
Jan 8, 2005

int i = 'j';
int j = 'i';


:supaburn:

nielsm
Jun 1, 2009



wlokos posted:

Right, I'm trying to turn the char argv[1][i] into an int. Would that look like
code:
int key[i] = (int)argv[1][i];
?

I thought wrapping it in apostrophes made it an int because I did things like
code:
if(message[i]>='a')
and it worked in the past, which I think I got from an example somewhere. But clearly I'm misunderstanding something about that.

The latter works because it's the value of a literal 'a' you want, not the value of something stored in a variable named 'a'.

The quotes signify a literal value: Single quotes (apostrophes) are character values, and double quotes are string values (character arrays implicitly terminated by a \0 character).

When you want to convert the value stored in a variable to a different data type, you use a typecast operator, as you do in your first code block here.

POKEMAN SAM
Jul 8, 2004

Vanadium posted:

int i = 'j';
int j = 'i';


:supaburn:

code:
printf("%d %d", i, j);

Stack Overflow

Harokey
Jun 12, 2003

Memory is RAM! Oh dear!
Exception Question:

Is there a way to create an exception class, that when thrown (and not caught) prints a meaningful error message?

What I have been getting is it will say something along the lines of:

code:
terminate called after throwing an instance of 'Picture::IndexOutOfBoundsException'
  what():  std::exception
Aborted
And its not printing out the contents of my what() function, which is what I want it to do.

That Turkey Story
Mar 30, 2003

Harokey posted:

Exception Question:

Is there a way to create an exception class, that when thrown (and not caught) prints a meaningful error message?

What I have been getting is it will say something along the lines of:

code:
terminate called after throwing an instance of 'Picture::IndexOutOfBoundsException'
  what():  std::exception
Aborted
And its not printing out the contents of my what() function, which is what I want it to do.

Not standard, no. Why do you want this? What's wrong with putting try/catch in main? If you're dealing with exceptions thrown from globals then you're stuck with wrapping your objects.

Adbot
ADBOT LOVES YOU

Harokey
Jun 12, 2003

Memory is RAM! Oh dear!

That Turkey Story posted:

Not standard, no. Why do you want this? What's wrong with putting try/catch in main? If you're dealing with exceptions thrown from globals then you're stuck with wrapping your objects.

I'm writing a C++ library that is used for CS1 courses. If this is the case, like It seems to be, I guess I'm better off just creating somewhat meaningful error messages and calling exit().

Edit: Which I've started to do, but wanted to make sure that there wasn't a way to do this with exceptions, because it seems to be the more "correct" way to do it.

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