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
Dijkstracula
Mar 18, 2003

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

Paniolo posted:

No you pedantic gently caress a 5 character array takes 5 bytes of memory.
You responded to somebody who just discovered that C-style strings are just arrays. Being pedantic over leaving room for that mysterious \0 is precisely what you want to be doing.

Adbot
ADBOT LOVES YOU

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

Dijkstracula posted:

You responded to somebody who just discovered that C-style strings are just arrays. Being pedantic over leaving room for that mysterious \0 is precisely what you want to be doing.

A better way to do that is to link them to the pertinent entries in the comp.lang.c faq imo

I'm too lazy to look for pertinent entries so I'll link these instead http://c-faq.com/aryptr/aryptr2.html http://c-faq.com/aryptr/aryptrequiv.html http://c-faq.com/decl/strlitinit.html

Sweeper
Nov 29, 2007
The Joe Buck of Posting
Dinosaur Gum
I'm not sure if this goes here, but it's in C++ so who knows! Basically I am using the windows API to create a clipboard manager of sorts, mostly as a learning utility. Now I can get the foreground window, AttachThreadInput and send the message WM_COPY, but it doesn't seem to work for all windows. I am guess this has to do with how the other program interprets WM_COPY. To get around this I want to grab the original data from the clipboard, send key strokes for ctrl+c, get new data, store it, and put the original data back.

This seems like a really bad way of doing this, is there any better way to grab selected text from a window?

Messages I have tried, WM_COPY (it inserts into the clipboard), WM_GETTEXT and EM_GETSELTEXT

shrughes
Oct 11, 2008

(call/cc call/cc)
Have you seen this talk?

http://www.galois.com/blog/2010/07/09/galois-tech-talk-video-large-scale-static-analysis-at-mozilla/

It seems like it would be interesting for C++ programmers (who aren't already ahead of the game like some people here).

FearIt
Mar 11, 2007
I'm having some trouble with a C++ project I'm writing that uses ImageMagick to convert images to different formats. The problem is happening with the system() command. When running in the Netbeans debugger I am getting an error saying the "sh: convert: command not found". But when I run the program from the terminal, everything works fine.

example code:
system("convert image1.tif image2.jpg");

I have tried to google the problem, but I cannot seem to find the answer.
Any idea what I am doing wrong?

pseudorandom name
May 6, 2007

FearIt posted:

I'm having some trouble with a C++ project I'm writing that uses ImageMagick to convert images to different formats. The problem is happening with the system() command. When running in the Netbeans debugger I am getting an error saying the "sh: convert: command not found". But when I run the program from the terminal, everything works fine.

example code:
system("convert image1.tif image2.jpg");

I have tried to google the problem, but I cannot seem to find the answer.
Any idea what I am doing wrong?

NetBeans is probably passing a bad $PATH to your program.

Also, you'd almost certainly be better off using the ImageMagick library directly instead of executing the programs yourself.

FearIt
Mar 11, 2007

pseudorandom name posted:

NetBeans is probably passing a bad $PATH to your program.

Also, you'd almost certainly be better off using the ImageMagick library directly instead of executing the programs yourself.


I manually set the $PATH in NetBeans and everything worked fine!
Thank you!

MrMoo
Sep 14, 2000

pseudorandom name posted:

Also, you'd almost certainly be better off using the ImageMagick library directly instead of executing the programs yourself.

I saw Alfresco does this from it's Java framework, people make some weird design decisions. I'm guessing said designers or developers never have to use or integrate their output; everyone else knows the less external dependencies the better. Java has it's own graphics API, I'm sure there is some equivalent for ImageMagick already created.

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.
Some of this was alright, some of it was really annoying (like anytime the guy laughed, told a nerd joke [usually followed by laughing], or started talking about how awesome Javascript is [also usually followed by laughing]). The de-emphasis of clang seems outdated already.

Crazy RRRussian
Mar 5, 2010

by Fistgrrl
how does #undef work in C/C++ exactly in case of multiple definitions of same name.

For example if I have

#define FOO BAR
#define FOO GAY

then do

#undef FOO

will FOO be empty or revert to BAR?

If no, is there a hack to make it have this stack behavior?

Vanadium
Jan 8, 2005

no

Jonnty
Aug 2, 2007

The enemy has become a flaming star!

Crazy RRRussian posted:

how does #undef work in C/C++ exactly in case of multiple definitions of same name.

For example if I have

#define FOO BAR
#define FOO GAY

then do

#undef FOO

will FOO be empty or revert to BAR?

If no, is there a hack to make it have this stack behavior?

There are two questions raised here. Firstly, why do you want to do that, and secondly, why haven't you stopped doing it yet?

Flobbster
Feb 17, 2005

"Cadet Kirk, after the way you cheated on the Kobayashi Maru test I oughta punch you in tha face!"
MSVC and gcc both support #pragma push_macro and pop_macro that can give you this behavior, but it's not standard C++. Don't use them. I don't know what other compilers, if any, support them.

The preprocessor is garbage.

king_kilr
May 25, 2007
The preprocessor is technically turing complete, and since turing complete is more powerful than a push down automata it must be emulatable. Why the gently caress do you need to do this?

Jonnty
Aug 2, 2007

The enemy has become a flaming star!

king_kilr posted:

The preprocessor is technically turing complete, and since turing complete is more powerful than a push down automata it must be emulatable. Why the gently caress do you need to do this?

Are you sure you're not mixing the preprocessor up with C++ templates? I'm not sure that's entirely true.

POKEMAN SAM
Jul 8, 2004

Jonnty posted:

Are you sure you're not mixing the preprocessor up with C++ templates? I'm not sure that's entirely true.

Yeah. The C preprocessor is not turing complete.

Crazy RRRussian
Mar 5, 2010

by Fistgrrl
The reason I wanted to do this is to use macros in small sections of code and to ensure that if they were used elsewhere that it is not altered by redefinition and then undef after I am done using it for code generation.

POKEMAN SAM
Jul 8, 2004

Crazy RRRussian posted:

The reason I wanted to do this is to use macros in small sections of code and to ensure that if they were used elsewhere that it is not altered by redefinition and then undef after I am done using it for code generation.

Oh I didn't see it was you, hexadecimal. My bad.

Jonnty
Aug 2, 2007

The enemy has become a flaming star!

Crazy RRRussian posted:

The reason I wanted to do this is to use macros in small sections of code and to ensure that if they were used elsewhere that it is not altered by redefinition and then undef after I am done using it for code generation.

Make sure your macro names are unique?

A MIRACLE
Sep 17, 2007

All right. It's Saturday night; I have no date, a two-liter bottle of Shasta and my all-Rush mix-tape... Let's rock.

.

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
This is perhaps a more generic CS kind of question but what is readily available in C++ is going to do a lot of determine what I end up doing.

Sometimes in various languages I run into a situation where I want to be able to readily look something up like with a hash but I also want to be able sort and order the data too. In languages like Perl or Python is go through the trouble of having both a list and a hash that walk along with each other. But I wonder if I should be looking at ordered maps or something else again. Generally is there a good, off-the-shelf data structure in a standard C++ implementation that could do this cleanly and potentially more efficiently?

I am particularly looking at STL's map:
http://www.cplusplus.com/reference/stl/map/

I wonder generally under the hood if it's efficient to iterate compared to, say, keeping a hash map and a linked list in sync.

Jonnty
Aug 2, 2007

The enemy has become a flaming star!

Rocko Bonaparte posted:

This is perhaps a more generic CS kind of question but what is readily available in C++ is going to do a lot of determine what I end up doing.

Sometimes in various languages I run into a situation where I want to be able to readily look something up like with a hash but I also want to be able sort and order the data too. In languages like Perl or Python is go through the trouble of having both a list and a hash that walk along with each other. But I wonder if I should be looking at ordered maps or something else again. Generally is there a good, off-the-shelf data structure in a standard C++ implementation that could do this cleanly and potentially more efficiently?

I am particularly looking at STL's map:
http://www.cplusplus.com/reference/stl/map/

I wonder generally under the hood if it's efficient to iterate compared to, say, keeping a hash map and a linked list in sync.

This is obviously not the thread but I noticed you mentioned Python - you might be interested to know that there's an ordered dictionary datatype that's been backported from Python 3 recently. You might even want to look at the source or the discussion surrounding it for tips on lower-level implementation of this sort of thing.

OddObserver
Apr 3, 2009

Rocko Bonaparte posted:


I wonder generally under the hood if it's efficient to iterate compared to, say, keeping a hash map and a linked list in sync.

It's a red-black tree or a comparable data structure (e.g. skip-list). So insertion/look ups, etc., are logarithmic cost, and /sorted/ traversal is linear.

king_kilr
May 25, 2007

Ugg boots posted:

Yeah. The C preprocessor is not turing complete.

mmm, I thought it was, via recursive includes. If not ignore me ;)

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!

OddObserver posted:

It's a red-black tree or a comparable data structure (e.g. skip-list). So insertion/look ups, etc., are logarithmic cost, and /sorted/ traversal is linear.

Oooh well that's better than I am using already, so I should play around with it at least. Looking at the template for STL's map, I am afraid of a little problem. I like to use pointers as keys, but I don't want to technically key on the address, but rather the value. With an unordered_map, it allows for a overridden hash function, so I could write my own function to hash against the dereferenced pointer instead. For map, I don't see anything that lets me using the value of pointers.

The problem will come about if I store something in a map using a key that's a pointer to, say, a string "foo" I allocated some place. Something else later have another string "foo" to look up in the map at a different allocated address. If it maps on the pointers then it won't find it, but if it maps on the string, then I assume I can find it. Is there a standard mapping structure that gives me that override?

Edit: I suppose it doesn't matter if there isn't considerable overhead in manipulating strings when adding and removing them from the map. I'm assuming it's more efficient to pass by reference.

Rocko Bonaparte fucked around with this message at 16:41 on Jul 14, 2010

Lexical Unit
Sep 16, 2003

Rocko Bonaparte posted:

For map, I don't see anything that lets me using the value of pointers.
I'm not entirely sure I understand your specific issue, but can't you use the Compare policy of std::map?

Rusty Kettle
Apr 10, 2005
Ultima! Ahmmm-bing!
I have a subroutine that does a special inversion that I made. I made an object called a "block" that contains a 12 by 12 array of complex <double> data types, as well as some various other pieces of data that specify what kind of block it is.

I am trying to pass a 300 by 3 array of these blocks to a subroutine but I am being told that it is being passed not as a block[300][3] but as a block(*)[3], and this creates a segmentation fault. I made a printf right under the initialization that will tell me if it gets past the beginning, but it doesn't.I have another subroutine does a similar passing thing, and it works just fine. So what is the difference between these two?

Broken one:
code:
void test_invert (block hmod2[300][3], complex <double> ener, double bf){ 
Working one:
code:
void init_grid (block stm[300][3], complex <double> ener, double bf){ 
They are in two different header files, and the main program includes both. I do not know what more information I can supply regarding this problem, so if you need more information, let me know.

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!

Lexical Unit posted:

I'm not entirely sure I understand your specific issue, but can't you use the Compare policy of std::map?

I think I see the problem. The map will sort by key, not value, right? I was hoping to sort by value, but also be able to recall something by a key.

Dooey
Jun 30, 2009
I have a Point<T> class that I am doing some debugging on and I've got a data logging macro that I would like to pass Points into and have them print out.

Slightly simplified, I want to be able to do this:

std::cout << aPoint;

and have it print (thePoints'X, thePoints'Y)

I tried defining operator char*() for the Point class and it worked the way I intended but I would have to delete the char* somewhere and that doesn't work with my data logging macro. So my questions:

1) is this even a good idea? its would come in very handy if I can make it work
2) is there any way to make my current method work?
3) is there another way to accomplish the same general effect that I am overlooking?

ChiralCondensate
Nov 13, 2007

what is that man doing to his colour palette?
Grimey Drawer

Dooey posted:

yearning for ostreams
Define a stand-alone function:
code:
std::ostream& operator<<(std::ostream& out, const Point& x) {
  out << "(" << x.x() << "," << x.y() << ")";
  return out; // so you can chain e.g.   cout << point1 << " " << point2 << "\n";
}
If your x() and y() methods aren't public you'll have to make that operator<<() a friend function. (Of course you can have some public member of Point do all its formatting and use that in operator<<().) Also, use std::string instead of char*.

Dooey
Jun 30, 2009
Thank you! Thats so much easier than all the other things I had tried.

Dooey fucked around with this message at 19:07 on Jul 14, 2010

litghost
May 26, 2004
Builder

Rocko Bonaparte posted:

I think I see the problem. The map will sort by key, not value, right? I was hoping to sort by value, but also be able to recall something by a key.

boost::bimap can do that. If you use an unordered_set_of for the keys, and set_of for the values, you will be able to search by key using a hash table, and iterate values in order.

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!

litghost posted:

boost::bimap can do that. If you use an unordered_set_of for the keys, and set_of for the values, you will be able to search by key using a hash table, and iterate values in order.

That's pretty hard core. I'll branch my toy project and try it on that over the weekend. I'm assuming it'll be faster if it can iterate with log(n) complexity.

HFX
Nov 29, 2004

Rocko Bonaparte posted:

That's pretty hard core. I'll branch my toy project and try it on that over the weekend. I'm assuming it'll be faster if it can iterate with log(n) complexity.

How can you possibly iterate with log(n) complexity? If you are iterating you are visiting every element which is an n operation on the lower bound. You could have n log (n).

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!

HFX posted:

How can you possibly iterate with log(n) complexity? If you are iterating you are visiting every element which is an n operation on the lower bound. You could have n log (n).
You are correct. I meant to insert and delete with log(n) complexity.

slovach
Oct 6, 2005
Lennie Fuckin' Briscoe


what the heck is this.

I dunno who Tim is or where Visual Studio is getting this from.

slovach fucked around with this message at 05:57 on Jul 16, 2010

HFX
Nov 29, 2004

slovach posted:



what the heck is this

Looks like an array of vectors for graphics. The F32 is probably a typedef for 32bit floats in a header file.

slovach
Oct 6, 2005
Lennie Fuckin' Briscoe

HFX posted:

Looks like an array of vectors for graphics. The F32 is probably a typedef for 32bit floats in a header file.

Sorry, I edited the post.

I mean... who is Tim and why does he show up. Those are coordinates I basically retyped out of a 3dsmax file. I dunno where Tim is coming from though.

slovach fucked around with this message at 06:01 on Jul 16, 2010

Dooey
Jun 30, 2009
Am I reading this right? YOU typed a bunch of numbers into an array and VS somehow came up with a comment about a guy named Tim? What on Earth...

Adbot
ADBOT LOVES YOU

Mr.Radar
Nov 5, 2005

You guys aren't going to believe this, but that guy is our games teacher.
The MSVCRT implementation of the exp function uses an array of coefficients named p which has that comment. Visual Studio must be sharing Intellisense data between the two.

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