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
very
Jan 25, 2005

I err on the side of handsome.
Thanks for your help. Apparently it was VC++'s retarded defaults for empty projects that got me again. I went through and made sure everything was the same as another project (it wasn't). It works now but I'm not even sure which option was the culprit. I guess I could pull the old one out of SVN if I really want to find out, but I'd rather forget about it.

Adbot
ADBOT LOVES YOU

Hyphen-ated
Apr 24, 2006
Not to be confused with endash or minus.
I am using VC++ 2005 express. I have sections of code that are #if'ed out sometimes. When editing this code, VC++ decides to gray it out and disable "go to definition" and friends in the context menu. This makes it more difficult to edit this code, which does actually get compiled sometimes. I would like it to treat all code as live code regardless of whether it looks like it will be compiled.

I can't find anything relevant in any of the config screens. How do I do this?

e: I can make the code not be grayed out from tools>options>text editor>c/c++>formatting, but that doesn't enable "go to definition"

Hyphen-ated fucked around with this message at 03:20 on Mar 19, 2008

more falafel please
Feb 26, 2005

forums poster

Hyphen-ated posted:

I am using VC++ 2005 express. I have sections of code that are #if'ed out sometimes. When editing this code, VC++ decides to gray it out and disable "go to definition" and friends in the context menu. This makes it more difficult to edit this code, which does actually get compiled sometimes. I would like it to treat all code as live code regardless of whether it looks like it will be compiled.

I can't find anything relevant in any of the config screens. How do I do this?

e: I can make the code not be grayed out from tools>options>text editor>c/c++>formatting, but that doesn't enable "go to definition"

Visual Assist can handle this, and it's Go To Definition isn't retarded like VS's is. Of course it's also money.

floWenoL
Oct 23, 2002

Is it legal to reinterpret_cast a char * to signed char * or unsigned char *? Some sources online indicate 'yes', but I can't find anything in the standard to back me up.

That Turkey Story
Mar 30, 2003

Yes.

floWenoL
Oct 23, 2002

That Turkey Story posted:

Yes.

I mean 'legal' as in it is guaranteed to do what you expect when you read from or write to the pointer. Can you give me where in the standard implies that? 5.2.10.7 seems to indicate otherwise:

5.2.10.7 posted:

A pointer to an object can be explicitly converted to a pointer to an object of different type.65) Except that converting an rvalue of type “pointer to T1” to the type “pointer to T2” (where T1 and T2 are object types
and where the alignment requirements of T2 are no stricter than those of T1) and back to its original type yields the original pointer value, the result of such a pointer conversion is unspecified.

JoeNotCharles
Mar 3, 2005

Yet beyond each tree there are only more trees.
A char is not an object.

WalletBeef
Jun 11, 2005

Has anyone been able to get Purify 7.0 properly working with Visual C++ in Visual Studio 2008, if so, what did you have to do to get both pieces of software working correctly?

I'm having a hell of a time getting purify to show me the exact line numbers where errors are occuring.

Right now, I get something like: Error at Class.obj:123
instead of Error at Class.cc:123.

For some reason purify isn't finding my source code, despite the fact that I specified the exact directory in the source look up.

Vanadium
Jan 8, 2005

JoeNotCharles posted:

A char is not an object.

Yes, it is.

Avenging Dentist
Oct 1, 2005

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

§3.9.1 #1 posted:

Objects declared as characters (char) shall be large enough to store any member of the implementation’s basic character set.
Probably the most direct answer from the standard.

Plastic Jesus
Aug 26, 2006

I'm cranky most of the time.

WalletBeef posted:

Has anyone been able to get Purify 7.0 properly working with Visual C++ in Visual Studio 2008, if so, what did you have to do to get both pieces of software working correctly?

I'm having a hell of a time getting purify to show me the exact line numbers where errors are occuring.

Right now, I get something like: Error at Class.obj:123
instead of Error at Class.cc:123.

For some reason purify isn't finding my source code, despite the fact that I specified the exact directory in the source look up.

It apparently doesn't work with VS 2008 PDB files. That' my guess, anyway. I was upgraded from 2005 to 2008 and started seeing exactly the problem that you describe. The good news is that the line numbers are accurate (though sometimes it will strangely specify the wrong object file). You just have to open them up outside of Purify.

WalletBeef
Jun 11, 2005

Plastic Jesus posted:

It apparently doesn't work with VS 2008 PDB files. That' my guess, anyway. I was upgraded from 2005 to 2008 and started seeing exactly the problem that you describe. The good news is that the line numbers are accurate (though sometimes it will strangely specify the wrong object file). You just have to open them up outside of Purify.

Well, I was afraid of that. The next logical step I was going to take was to uninstall 2008 and go with 2005. :smith: Thanks

Erwin
Feb 17, 2006

Horrible newbie question:

In this code:
code:
sprintf (ProdChar, "%d", Product);
...is there any reason that an int called Greatest that has nothing to do with this line would change? If I cout << Greatest just before and just after the line, the output is
code:
9009
8960
But once it's 8960, it stays 8960 even though it goes through this line several more times. Witchcraft is the only explanation I can come up with. :tinfoil:

VV That's the ticket. I bumped ProdChar's size up by one and it fixed it. Thanks!

Erwin fucked around with this message at 13:16 on Mar 20, 2008

TSDK
Nov 24, 2003

I got a wooden uploading this one

Erwin posted:

Horrible newbie question:

In this code:
code:
sprintf (ProdChar, "%d", Product);
...is there any reason that an int called Greatest that has nothing to do with this line would change? If I cout << Greatest just before and just after the line, the output is
code:
9009
8960
But once it's 8960, it stays 8960 even though it goes through this line several more times. Witchcraft is the only explanation I can come up with. :tinfoil:
You've not counted the zero terminator when working out ProdChar's size.

How do I know?

9009 = 0x2331
8960 = 0x2300

So the least significant byte of Greatest has been stomped on. Which then tells me you're running on a little endian machine, and that ProdChar and Greatest have been declared right next to each other.

WalletBeef
Jun 11, 2005

Plastic Jesus posted:

It apparently doesn't work with VS 2008 PDB files. That' my guess, anyway. I was upgraded from 2005 to 2008 and started seeing exactly the problem that you describe. The good news is that the line numbers are accurate (though sometimes it will strangely specify the wrong object file). You just have to open them up outside of Purify.

Well, I installed VS 2005 and Purify is happy. It's showing line numbers, source code and all. Thanks a loving ton. :unsmith:

graffin
Sep 28, 2002
Is there a way to test if an Object element variable is an integer, string, or char string?

Steampunk Mario
Aug 12, 2004

DIAGNOSIS ACQUIRED

graffin posted:

Is there a way to test if an Object element variable is an integer, string, or char string?

Are you talking about C# or something? C++ is too strongly typed to cleanly support a standard Object type, but Java and C# do.

graffin
Sep 28, 2002

Drx Capio posted:

Are you talking about C# or something? C++ is too strongly typed to cleanly support a standard Object type, but Java and C# do.

I'm using it in C++, in the context of a template for a binary tree based dictionary. The object is an element in a node. In the dictionary, I'm trying to test the element to determine if it is an int or string.

haveblue
Aug 15, 2005



Toilet Rascal

graffin posted:

I'm using it in C++, in the context of a template for a binary tree based dictionary. The object is an element in a node. In the dictionary, I'm trying to test the element to determine if it is an int or string.

C++ doesn't have any facility for determining what basic type a symbol is, RTTI only works on classes.

Also, if your template class has to implement different functionality based on the type of the varying element, you may want to revisit its design.

Standish
May 21, 2001

graffin posted:

I'm using it in C++, in the context of a template for a binary tree based dictionary. The object is an element in a node. In the dictionary, I'm trying to test the element to determine if it is an int or string.
http://codepad.org/cTLm8Woy

Standish fucked around with this message at 20:19 on Mar 20, 2008

graffin
Sep 28, 2002

Standish posted:

http://codepad.org/cTLm8Woy

Cool. Thanks.

Lexical Unit
Sep 16, 2003

graffin posted:

I'm using it in C++, in the context of a template for a binary tree based dictionary. The object is an element in a node. In the dictionary, I'm trying to test the element to determine if it is an int or string.
I'm not sure exactly what you're trying to do or why, but type_traits might be applicable/helpful.

elevatordeadline
Jan 29, 2008
Teach me about 64-bit integers in C.

In Java, int is four bytes and long is eight bytes. That's not the case in C, where, if I understand correctly, sizeof(long) only has to be at least equal to sizeof(int). So what should I do when I need a 64-bit integer?

Scaevolus
Apr 16, 2007

elevatordeadline posted:

Teach me about 64-bit integers in C.

In Java, int is four bytes and long is eight bytes. That's not the case in C, where, if I understand correctly, sizeof(long) only has to be at least equal to sizeof(int). So what should I do when I need a 64-bit integer?

#include <stdint.h>

This gives typedefs that include number of bits, like uint8_t for unsigned 8-bit integers, and int32_t for signed 32-bit integers. Only up to 32 bits are required, but your implementation might have int64_t and uint64_t.

Steampunk Mario
Aug 12, 2004

DIAGNOSIS ACQUIRED

elevatordeadline posted:

Teach me about 64-bit integers in C.

In Java, int is four bytes and long is eight bytes. That's not the case in C, where, if I understand correctly, sizeof(long) only has to be at least equal to sizeof(int). So what should I do when I need a 64-bit integer?

I'm not 100% about the standardization of these, but I'm pretty sure 'long long' and 'int64_t' are 64-bit.

elevatordeadline
Jan 29, 2008
uint64_t and unsigned long long both work as long as I'm using gcc -std=c99. Hooray. Evidently, though, I don't understand what to do next.

For example,
code:
typedef unsigned long long ulong;

ulong x, y, z;
printf("%llu bytes.\n", (ulong) sizeof(ulong));
scanf("%llu %llu %llu", &x, &y, &z);
printf("x = %llu,\ny = %llu,\nz = %llu.\n", x, y, z);
If the input is 314, 31415926535897, and 6469693230, then the output is
code:
8 bytes.
x = 314,
y = 2147303424,
z = 2535732953.
Those numbers are not the same numbers at all. :(

Plastic Jesus
Aug 26, 2006

I'm cranky most of the time.

WalletBeef posted:

Well, I installed VS 2005 and Purify is happy. It's showing line numbers, source code and all. Thanks a loving ton. :unsmith:

np. I've tried various cl.exe and link.exe switches and I can't get VS2008 to generate the old-style PDB files. I'm a deeply lazy man, though, and don't feel like going back to 2005. I also have a weirdish development environment (I mount my windows drive from my mac and edit everything in vim), so I'm used to just opening the source files and finding the offending lines. Hopefully, though, IBM will release a fix soon enough. I don't know if you've tried dealing with IBM support yet but DO NOT attempt to submit this as a bug. You'll end up with a self-inflicted bullet wound.

Steampunk Mario
Aug 12, 2004

DIAGNOSIS ACQUIRED

elevatordeadline posted:

uint64_t and unsigned long long both work as long as I'm using gcc -std=c99. Hooray. Evidently, though, I don't understand what to do next.

For example,
code:
typedef unsigned long long ulong;

ulong x, y, z;
printf("%llu bytes.\n", (ulong) sizeof(ulong));
scanf("%llu %llu %llu", &x, &y, &z);
printf("x = %llu,\ny = %llu,\nz = %llu.\n", x, y, z);
If the input is 314, 31415926535897, and 6469693230, then the output is
code:
8 bytes.
x = 314,
y = 2147303424,
z = 2535732953.
Those numbers are not the same numbers at all. :(

I don't recognize those format characters, so I'm assuming you have some extension of printf that does. Are you sure it's reading/writing 8 bytes?

Scaevolus
Apr 16, 2007

elevatordeadline posted:

Those numbers are not the same numbers at all. :(

Works for me on x86_64 (:woop: native 64-bit integers), gcc version 4.2.3
code:
8 bytes.
314 31415926535897 6469693230
x = 314,
y = 31415926535897,
z = 6469693230.

Lexical Unit
Sep 16, 2003

elevatordeadline, you're code works fine on my 64bit MacBook Pro running OS X 10.5 with gcc version 4.0.1 and also on a 32bit RHEL4AS machine with gcc version 3.4.6. You might open up your inttypes.h file and see what's in there. You may not find a perfectly portable solution, unfortunately.

elevatordeadline
Jan 29, 2008

Lexical Unit posted:

You might open up your inttypes.h file and see what's in there. You may not find a perfectly portable solution, unfortunately.

code:
/* 7.8.1 Macros for format specifiers
 * 
 * MS runtime does not yet understand C9x standard "ll"
 * length specifier. It appears to treat "ll" as "l".
 * The non-standard I64 length specifier causes warning in GCC,
 * but understood by MS runtime functions.
 */
Oh, okay. Well, it's a good thing that this program's only going to be tested and run on a Linux machine that does understand "ll." Thanks, guys.

chris_bacon
Feb 27, 2008
I'm working on a blackjack program for my c++ class, but I'm having trouble working with all the separate files. When I compile the driver program, I get:

code:
realgar% g++ driver.cpp
/tmp/ccVQ0FJW.o: In function `dealCards(Deck, SimplePlayer, Hand)':
driver.cpp:(.text+0xcc3): undefined reference to `SimplePlayer::expose(Card)'
driver.cpp:(.text+0xd39): undefined reference to `SimplePlayer::expose(Card)'
driver.cpp:(.text+0xd63): undefined reference to `SimplePlayer::expose(Card)'
collect2: ld returned 1 exit status
SimplePlayer is a class in I defined in a file called player.cpp, and I #included "player.cpp" so I'm not sure what the problem is here. Do I need to also define SimplePlayer in player.h ?

ColdPie
Jun 9, 2006

chris_bacon posted:

I'm working on a blackjack program for my c++ class, but I'm having trouble working with all the separate files. When I compile the driver program, I get:

code:
realgar% g++ driver.cpp
/tmp/ccVQ0FJW.o: In function `dealCards(Deck, SimplePlayer, Hand)':
driver.cpp:(.text+0xcc3): undefined reference to `SimplePlayer::expose(Card)'
driver.cpp:(.text+0xd39): undefined reference to `SimplePlayer::expose(Card)'
driver.cpp:(.text+0xd63): undefined reference to `SimplePlayer::expose(Card)'
collect2: ld returned 1 exit status
SimplePlayer is a class in I defined in a file called player.cpp, and I #included "player.cpp" so I'm not sure what the problem is here. Do I need to also define SimplePlayer in player.h ?

Never include .cpp files. The header files (.h) contain information about the class that other files need to know -- basically, what functions/members are a part of the class. The source files (.cpp) contain definitions for the functions. A simple example:

Player.h (lay out the interface)
code:
#ifndef PLAYER_H
#define PLAYER_H

class Player {
public:
    Player();
    virtual ~Player();

    void doSomething();

private:
    int aNumber;
};

#endif
Player.cpp (define the function implementations)
code:
#include "Player.h"

Player::Player()
{
    aNumber = 17;
}

Player::~Player(){}

void Player::doSomething()
{
    aNumber += 5;
}
Driver.cpp (use the interface laid out in Player.h)
code:
#include "Player.h"

int main(int argc, char** argv)
{
    Player player;
    player.doSomething();

    return 0;
}
Notice that Driver.cpp does not include Player.cpp, but rather Player.h. Player.h contains just the interface for the Player class, nothing more. The actual implementation is contained within Player.cpp, where it belongs. Driver.cpp doesn't care how Player is implemented; it only cares about which functions and members are contained within Player.

Once you start dealing with inlines and templated code, things will be a little more complicated. But at your level, the above holds true.

ColdPie fucked around with this message at 04:18 on Mar 22, 2008

chris_bacon
Feb 27, 2008
Alright, one more related question. Whenever I try to compile deck.cpp, I get this error:

code:
rubric% g++ deck.cpp
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: ld returned 1 exit status
I have no idea what could cause this. I didn't make an int main in deck.cpp, and I only included "deck.h" which also does not contain anything referring to 'main'. Any ideas?

haveblue
Aug 15, 2005



Toilet Rascal
That error means that there is no main function anywhere that gcc can find. It's trying to produce an executable and can't figure out where your code takes over once the process is created.

Where is main? Is there a path of includes leading to it from deck.cpp? If you want to produce an object file for linking later you have to use a different invocation of gcc.

chris_bacon
Feb 27, 2008

HB posted:

That error means that there is no main function anywhere that gcc can find. It's trying to produce an executable and can't figure out where your code takes over once the process is created.

Where is main? Is there a path of includes leading to it from deck.cpp? If you want to produce an object file for linking later you have to use a different invocation of gcc.

ah, I forgot to add -c when compiling. thanks for the help.

Dransparency
Jul 19, 2006
I'm having some trouble getting standard iterators to work, and google isn't giving me much help.

Currently I have something like this:

code:
#include <vector>

template<typename itemType>
class Foo
{
   typedef std::iterator<std::forward_iterator_tag, itemType> Iterator;
   bool exists(Iterator& beg, Iterator& end) const;
};

int main()
{
   std::vector<int> vals;
   //fill with values
   Foo<int> test;
   test.exists(vals.begin(), vals.end());
}
I got the typedef off of some sites I found, but it's difficult to find documentation for the std::iterator class itself.

When I compile (using VS2008) I get an error saying:
code:
'...cannot convert parameter 1 from 'std::_Vector_iterator<_Ty,_Alloc>' to 'std::iterator<_Category,_Ty> &'
This suggests to me that either the iterators used by the STL aren't derived from the std::iterator class or I'm using the wrong template arguments for std::iterator.

Is there another class I should be deriving from or different template arguments I should be providing to std::iterator? The only requirements I have for the iterator are that it can advance forward and check for equality with other iterators (as well as access whatever it points to, obviously).

I've noticed that the functions in the <algorithms> header just use templates that take any old class as an iterator, leaving it up to the user to make sure it supplies the proper operations. I would assume that is because they need to support pointers as well as actual iterator classes. Even though I don't need the support for pointers, would this be a better approach for my problem? I've been avoiding it so far because I want to make this as standardized as possible, plus I don't know the syntax for a member function with additional template parameters from its class. Can I just use nested templates?

floWenoL
Oct 23, 2002

Dransparency posted:

Even though I don't need the support for pointers, would this be a better approach for my problem?

Yes.

quote:

I've been avoiding it so far because I want to make this as standardized as possible, plus I don't know the syntax for a member function with additional template parameters from its class. Can I just use nested templates?

Yes. Depending on what exactly class Foo is supposed to do, there might not even be a need for it.

Vanadium
Jan 8, 2005

Internet research reveals that std::iterator is not supposed to be used as a base class for iterators. The entire point of the whole generic programming thing is that you do not need to derive from stupid classes just to make functions work on your types. std::iterators provide some typedefs to help meeting the iterator requirements I guess.

The definition given in the standard is

code:
namespace std {
  template<class Category, class T, class Distance = ptrdiff_t,
           class Pointer = T*, class Reference = T&>
  struct iterator {
        typedef T         value_type;
        typedef Distance difference_type;
        typedef Pointer   pointer;
        typedef Reference reference;
        typedef Category iterator_category;
  };
}

Adbot
ADBOT LOVES YOU

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
Hopefully, in C++0x, there will just be an "iterator" concept. The more I think about concepts, the more I like them.

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