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
Jam2
Jan 15, 2008

With Energy For Mayhem
I want my CVector to store pointers. However, no matter how much indirection I add, it tries to dereference the variables to perform copy ops on primitive data.

How should I structure the CVectorCreate call?
code:
CVectorCreate(sizeof(char *), EST_INPUT_SIZE, NULL);
The above allows me to store 4 chars when called with:

code:
CVectorAppend(CVector, char *);
I want to store a pointer though. And
code:
CVectorAppend(CVector, &(char *));
doesn't work.

Adbot
ADBOT LOVES YOU

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
What does your actual call site look like?

The problem with simplifying problems to ask other people is that sometimes you simplify them too much and get rid of actually useful detail.

Jam2
Jan 15, 2008

With Energy For Mayhem

Jabor posted:

What does your actual call site look like?

The problem with simplifying problems to ask other people is that sometimes you simplify them too much and get rid of actually useful detail.

code:
char temp[i+ 1];
for (int j = 0; j <= i; j++)
    temp[j] = buffer[j];
CVectorAppend(v, temp);

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Jam2 posted:

code:
char temp[i+ 1];
for (int j = 0; j <= i; j++)
    temp[j] = buffer[j];
CVectorAppend(v, temp);

The first thing I'm going to say is that storing a pointer to something allocated on the stack is usually a bug waiting to happen.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

Jam2 posted:

code:
char temp[i+ 1];

Is that even legal C? I thought you had to use alloca or something.

shrughes
Oct 11, 2008

(call/cc call/cc)

Suspicious Dish posted:

Is that even legal C? I thought you had to use alloca or something.

It's valid C99.

Jam2
Jan 15, 2008

With Energy For Mayhem

Jabor posted:

The first thing I'm going to say is that storing a pointer to something allocated on the stack is usually a bug waiting to happen.

But it doesn't even do that.
And when I try to Malloc and store I get the same result. It has to do with the vectors element size

Chillbro_69
Jul 23, 2006

Is putting something like "rmask = 0xff000000;" into an unsigned 32-bit integer actually valid?

Vanadium
Jan 8, 2005

That just about fits, doesn't it?

Chillbro_69
Jul 23, 2006

I think so, but VC++ is giving me errors like:

- error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
- error C2371: 'rmask' : redefinition; different basic types

Heres the full block:

code:
Uint32 rmask, gmask, bmask, amask;

#if SDL_BYTEORDER == SDL_BIG_ENDIAN
    rmask = 0xff000000;
    gmask = 0x00ff0000;
    bmask = 0x0000ff00;
    amask = 0x000000ff;
#else
    rmask = 0x000000ff;
    gmask = 0x0000ff00;
    bmask = 0x00ff0000;
    amask = 0xff000000;
#endif
I'm trying to make masks to pass to SDL_CreateRGBSurface

Chillbro_69 fucked around with this message at 14:20 on Feb 25, 2012

Vanadium
Jan 8, 2005

Sounds like you're trying to put expressions (assignments) into the top-level scope. You can initialise variables as you're declaring them, but you can't declare them and then assing to them.

Chillbro_69
Jul 23, 2006

Vanadium posted:

Sounds like you're trying to put expressions (assignments) into the top-level scope. You can initialise variables as you're declaring them, but you can't declare them and then assing to them.

Yep, that was it. Thanks

Flobbster
Feb 17, 2005

"Cadet Kirk, after the way you cheated on the Kobayashi Maru test I oughta punch you in tha face!"
Does anyone know of an easy to use library or other reusable code, written in C or C++, that can take a human-readable function or type name and mangle it using gcc's ABI, respecting all of the shortcuts and substitutions defined there?

Ideally I'd like something like this:

code:
mangle("foo(int)")  // returns "_Z3fooi"
mangle("foo(int (*)(int), int)")  // returns "_Z3fooPFiiEi"
mangle("foo::bar(string)")  // returns "__ZN3foo3barESs"
I promise there's a legitimate and cool reason that I need this. Or have I gone mad?

litghost
May 26, 2004
Builder

Flobbster posted:

Does anyone know of an easy to use library or other reusable code, written in C or C++, that can take a human-readable function or type name and mangle it using gcc's ABI, respecting all of the shortcuts and substitutions defined there?

Ideally I'd like something like this:

code:
mangle("foo(int)")  // returns "_Z3fooi"
mangle("foo(int (*)(int), int)")  // returns "_Z3fooPFiiEi"
mangle("foo::bar(string)")  // returns "__ZN3foo3barESs"
I promise there's a legitimate and cool reason that I need this. Or have I gone mad?

I think GNU binutils has demangle.h which can go in both directions.

Flobbster
Feb 17, 2005

"Cadet Kirk, after the way you cheated on the Kobayashi Maru test I oughta punch you in tha face!"

litghost posted:

I think GNU binutils has demangle.h which can go in both directions.

Hmm, I dug through the binutils source and didn't see anything in demangle.h that indicated that it did mangling as well as demangling (except for a random function to mangle an operator name).

I was hoping this was already a solved problem since (1) I don't want to have to dig through gcc's source code, and (2) gcc's mangling is probably based on ASTs anyway rather than the text representation of the function declaration.

I feel like I'm going to be forced to implement a small function prototype parser and do the mangling myself if I want to do this.

Vanadium
Jan 8, 2005

If you consider function argument types defined via template metaprogramming, you are gonna have to implement a frighteningly large part of C++ for that. Or even something like void f(int (&)[sizeof(FILE)]);

Flobbster
Feb 17, 2005

"Cadet Kirk, after the way you cheated on the Kobayashi Maru test I oughta punch you in tha face!"

Vanadium posted:

If you consider function argument types defined via template metaprogramming, you are gonna have to implement a frighteningly large part of C++ for that. Or even something like void f(int (&)[sizeof(FILE)]);

Yeah, yuck.

For now I'd be happy with supporting simple global functions and class methods/ctors/dtors, where your arguments wouldn't be more involved than primitives, some STL classes, and user defined data types. This is intended to be part of a library of support code for intro C++ courses, where students wouldn't be defining anything too bizarre.

Paolomania
Apr 26, 2006

If its part of a course just use the hack-OO C way...
code:
foo* foo_with_int(int)
foo* foo_with_func_and_int( int (*) (int), int )
void foo_bar(foo* this, string)
... and then later in the course when you let them use real C++ say "Presto magico! Isn't overloading awesome!?"

Flobbster
Feb 17, 2005

"Cadet Kirk, after the way you cheated on the Kobayashi Maru test I oughta punch you in tha face!"

Paolomania posted:

If its part of a course just use the hack-OO C way...
code:
foo* foo_with_int(int)
foo* foo_with_func_and_int( int (*) (int), int )
void foo_bar(foo* this, string)
... and then later in the course when you let them use real C++ say "Presto magico! Isn't overloading awesome!?"

Absolutely not :colbert: This isn't student-facing code anyway -- I'm doing things to make certain runtime analysis of student code easier, and I'm trying to eliminate the step where I have to run "nm" to get the mangled names first.

I've decided to just write a simple parser for now -- 99% of the cases I'm working with involve basic arguments, so writing mangle("foo(int, const char*)") and getting back "_Z3fooiPKc" is pretty easy to whip up.

If and when I decide I need it, I'll just snag the appropriate part of the C++ grammar and build a parser from that, which should cover just about all the behavior someone in my position might need (as long as they stay away from horrible examples like Vanadium's).

Paolomania
Apr 26, 2006

Ah, I thought this was for pedagogical reasons. I like the idea of first teaching someone how to structure a class without the compiler enforcing it. That way when you show them C++ syntax it impresses upon them what the compiler is actually doing and why it makes their life easier.

Chillbro_69
Jul 23, 2006

If I wanted to make a drawing area or viewer inside of a GTK+/GTKmm window, what library might be the best bet to use?

floWenoL
Oct 23, 2002

Flobbster posted:

If and when I decide I need it, I'll just snag the appropriate part of the C++ grammar and build a parser from that, which should cover just about all the behavior someone in my position might need (as long as they stay away from horrible examples like Vanadium's).

You seem to be unaware of how complicated the C++ grammar really is.

You could always shell out; that may be the most practical option.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

Hurricane human being posted:

If I wanted to make a drawing area or viewer inside of a GTK+/GTKmm window, what library might be the best bet to use?

GtkDrawingArea?

Cyril Sneer
Aug 8, 2004

Life would be simple in the forest except for Cyril Sneer. And his life would be simple except for The Raccoons.
Okay this is kind of specific, hopefully someone can help.

I'm currently taking a CUDA optimization course (CUDA being an NVIDIA GPU). Code is written in C/C++.

Things are currently set up such that we can access the hardware and compiler remotely via ssh - this way we are not forced to go into a computer lab (remember the code is programmed for / compiled to / must be run on the CUDA hardware).

The only thing is its a pain in the rear end using ssh for doing coding (duh). I'm trying to wrap my head around how to write the code locally, and just somehow upload it, but it doesn't seem like there's an obvious way to do it.

I guess I could look into local compilation and running it on an emulator of some sort to test it prior to uploading it to my school's linux network.

*sigh* I dunno. This is probably too specific for here, but its worth a shot.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
sounds like a great time to learn how to use vim

Zhentar
Sep 28, 2003

Brilliant Master Genius
Or X forwarding.

OddObserver
Apr 3, 2009
if you can use ssh, you may e able to use scp or sftp.

Computer viking
May 30, 2011
Now with less breakage.

OddObserver posted:

if you can use ssh, you may e able to use scp or sftp.

Almost certainly. If he's running windows locally, there's a few alternatives that can work with that, e.g. komodoEdit. (I used kate from kde4/windows last time it came up, but that's honestly only recommended for the kind of people that happen to already have it installed.)

Flobbster
Feb 17, 2005

"Cadet Kirk, after the way you cheated on the Kobayashi Maru test I oughta punch you in tha face!"

floWenoL posted:

You seem to be unaware of how complicated the C++ grammar really is.

You could always shell out; that may be the most practical option.

No, actually I'm totally aware of it, which is why I'm avoiding having to exercise that option as long as possible.

I would only need a reasonable subset of valid function headers, and I'm not terribly concerned with esoteric cases -- people using my library wouldn't be plugging in functions that take templated pointer-to-member arguments with const volatile modifiers or anything like that.

...which is why the very rudimentary tokenizer I wrote is doing the job just fine so far, anyway.

pseudorandom name
May 6, 2007

What was that legitimate and cool thing you were doing, again?

Cyril Sneer
Aug 8, 2004

Life would be simple in the forest except for Cyril Sneer. And his life would be simple except for The Raccoons.

Computer viking posted:

Almost certainly. If he's running windows locally, there's a few alternatives that can work with that, e.g. komodoEdit. (I used kate from kde4/windows last time it came up, but that's honestly only recommended for the kind of people that happen to already have it installed.)

Can you elaborate on this a bit?

ToxicFrog
Apr 26, 2008


Cyril Sneer posted:

The only thing is its a pain in the rear end using ssh for doing coding (duh). I'm trying to wrap my head around how to write the code locally, and just somehow upload it, but it doesn't seem like there's an obvious way to do it.

There's a whole bunch of ways if you're on Linux:
- remote-mount the entire remote system over SSH; edit the files locally, as you would anything else on a networked drive
- use git or another DVCS that supports SSH, possibly with a post-commit hook to automatically upload your changes
- use rsync or, failing that, scp to upload your changes before compilations
- install Dropbox on both systems, use that
- use an editor with built-in sshfs support (I can't name any offhand but I'm pretty sure they exist)

If you're on Windows, it's a bit uglier - mounting the system over SSH isn't an option, and while windows ports of most of these tools exist they often aren't as pleasant to install or use. In that case, dropbox or an editor with sshfs support are probably your best bets.

If you're on OSX I have no clue.

taqueso
Mar 8, 2004


:911:
:wookie: :thermidor: :wookie:
:dehumanize:

:pirate::hf::tinfoil:

I've used sshfs for OSX, it was a little rough but that was a couple years ago. Dokan is a userspace filesystem for Windows that claims to have sshfs. Just found that by searching, so I dunno if it is any good.

It could also be an excuse to learn vim.

Flobbster
Feb 17, 2005

"Cadet Kirk, after the way you cheated on the Kobayashi Maru test I oughta punch you in tha face!"

pseudorandom name posted:

What was that legitimate and cool thing you were doing, again?

I don't want to give away all the details because I'm planning to do get a conference publication or two out of this :v:

But basically, we do a lot of automated grading of assignments in CS classes, and students aren't always good about declaring their functions correctly (get the parameters wrong, or name it wrong, stuff like that). If an instructor writes a test harness that links directly to the student's code and functions are missing, it won't even compile and the student gets less than ideal feedback. If the assignment includes 10 functions and the student messed up on one of them, I want to be able to give them feedback for the other 9, instead of having compiler/linker errors kill the whole thing.

So what I want to be able to do instead is look at the exported symbols of the executable and dynamically load the functions, and wrap that in a nice API that instructors can use. (Essentially a weak kind of reflection.)

I've already got it working if I give it the mangled name directly, so I'm just trying to improve the API at this point.

Modern Pragmatist
Aug 20, 2008

ToxicFrog posted:

There's a whole bunch of ways if you're on Linux:
- remote-mount the entire remote system over SSH; edit the files locally, as you would anything else on a networked drive
- use git or another DVCS that supports SSH, possibly with a post-commit hook to automatically upload your changes
- use rsync or, failing that, scp to upload your changes before compilations
- install Dropbox on both systems, use that
- use an editor with built-in sshfs support (I can't name any offhand but I'm pretty sure they exist)

If you're on Windows, it's a bit uglier - mounting the system over SSH isn't an option, and while windows ports of most of these tools exist they often aren't as pleasant to install or use. In that case, dropbox or an editor with sshfs support are probably your best bets.

If you're on OSX I have no clue.

OS X options are basically the same as linux in this case.

Thirding vim. This is the biggest advantage of vim in my opinion and it's not all that hard to learn the basics.

Honestly, if you're on windows, you'd be better off installing a Linux VM to access the remote machine just because it gives you more options. (Assuming you don't want to spend the time to learn vim)

OneEightHundred
Feb 28, 2008

Soon, we will be unstoppable!
If you're on Windows and the remote store has SCP or SFTP, then WinSCP has a "keep up to date" feature that keeps a local and remote folder in sync.

EnzoMafo
Jul 29, 2008
I'm looking for recommendations for a performance analysis tool. For some reason our apps are having trouble working with PGPROF, and so I've been asked to investigate alternatives. Does anyone have one that they have had favorable experiences with that I can look into? My general requests being only that it profiles C++ and handles multiple threads well.

Zakath
Mar 22, 2001

I'm writing a program in C++ that passes some pointers around that I really don't want modified, some I'm doing the const int* const* blah blah thing. Then I noticed that I can write
code:
const bool* boolPtr;

bool what = boolPtr;
and GCC doesn't throw any kind of errors, unlike if I replace that bool with an int or any other primitive, which will then give me the "invalid conversion" error, which is the behavior I want. Can someone explain this? Can I force the compiler to throw an error on this sort of thing?

shrughes
Oct 11, 2008

(call/cc call/cc)

Zakath posted:

I can write
code:
const bool* boolPtr;

bool what = boolPtr;

That is assigning to what the value true if boolPtr is not NULL, and false if boolPtr is NULL. That is, your code's equivalent to

code:
const bool* boolPtr;
bool what = (boolPtr != NULL);
I don't think there's a warning for this, because implicit pointer-to-boolean conversions are very common in C++.

This has nothing to do with your use of const pointers, so I'm not sure why you're including that information in your question.

Adbot
ADBOT LOVES YOU

Zakath
Mar 22, 2001

shrughes posted:

That is assigning to what the value true if boolPtr is not NULL, and false if boolPtr is NULL. That is, your code's equivalent to

code:
const bool* boolPtr;
bool what = (boolPtr != NULL);
I don't think there's a warning for this, because implicit pointer-to-boolean conversions are very common in C++.

This has nothing to do with your use of const pointers, so I'm not sure why you're including that information in your question.
You're right, it was just what led me to this, and has no bearing on my question.

Is there any way of checking for this kind of undesired assignment?

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