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
Volte
Oct 4, 2004

woosh woosh
I always make sure to disable the Microsoft language extensions in the project options (I believe it's in the 'Language' section). That should keep your code relatively clean so it can be ported away from Visual C++ fairly easily. It may take away 64-bit integers all together though since C++ doesn't have one in the standard.

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
Since there doesn't appear to be a Win32 questions thread, I'll just ask this here: given a PIDL, how does one open the file identified by that PIDL? I know you could convert the PIDL to its display name and use I/O streams, but I think that would fail for stuff that's not a real filesystem object...

vanjalolz
Oct 31, 2006

Ha Ha Ha HaHa Ha
Can someone explain what I'm doing wrong with semaphores here: http://codepad.org/4MXCzn9o

On OSX it compiles, but on fedora it fails to link:

sem.c:(.text+0x59): undefined reference to `sem_wait'
sem.c:(.text+0x8e): undefined reference to `sem_post'


edit:
Ok -lpthread to compile, but the output is still wonky.

vanjalolz fucked around with this message at 06:32 on May 25, 2008

Allie
Jan 17, 2004

vanjalolz posted:

Can someone explain what I'm doing wrong with semaphores here: http://codepad.org/4MXCzn9o

On OSX it compiles, but on fedora it fails to link:

sem.c:(.text+0x59): undefined reference to `sem_wait'
sem.c:(.text+0x8e): undefined reference to `sem_post'


You probably need to tell GCC to link to it with -lpthread. OS X shoves a lot of POSIX functions into one huge library (libSystem) which is probably why it worked there.

Also, your code doesn't actually compile for me with gcc 4.1 (due to type assignment/argument errors), but I'm guessing you just need to link to that library. I would install the dev man pages for your distribution and make sure you're using the API correctly.

Allie fucked around with this message at 06:44 on May 25, 2008

vanjalolz
Oct 31, 2006

Ha Ha Ha HaHa Ha
Yeah theres something weird about these semaphore functions. I think I'm mixing different implementations because some accept sem_t, others accept an int.

This is the code I have now which compiles and runs on fedora, and no longer returns errors from sempost/wait: http://codepad.org/EJVgLXin

What's the easiest way to get counting semaphores on posix which continue to work after a fork()?

edit: drat, sem_init not implemented on osx :/

Zombywuf
Mar 29, 2008

Smackbilly posted:

The context is that I'm writing an app that does asynchronous communication over UDP. Since UDP is unreliable, certain packets that are not ACK'ed after a timeout need to be re-sent. The way I'm currently handling this is:

Why are you emulating TCP?

Avenging Dentist
Oct 1, 2005

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

Avenging Dentist posted:

Since there doesn't appear to be a Win32 questions thread, I'll just ask this here: given a PIDL, how does one open the file identified by that PIDL? I know you could convert the PIDL to its display name and use I/O streams, but I think that would fail for stuff that's not a real filesystem object...

I think I figured this out. For the curious, I grabbed the desktop IShellFolder instance with SHGetDesktopFolder and then pulled out an IStream with BindToStorage.

Smackbilly
Jan 3, 2001
What kind of a name is Pizza Organ! anyway?

Zombywuf posted:

Why are you emulating TCP?

1. I didn't write the protocol
2. Not all packets are ACK'ed, only certain important packets
3. I'm not emulating TCP connections or flow control

more falafel please
Feb 26, 2005

forums poster

Zombywuf posted:

Why are you emulating TCP?

TCP is not always necessary.

Zombywuf
Mar 29, 2008

more falafel please posted:

TCP is not always necessary.

No, but if you're ACKing packets it's usually the better option. But it seems Smackbilly has no say in the protocol so it's moot anyway.

haveblue
Aug 15, 2005



Toilet Rascal

Zombywuf posted:

No, but if you're ACKing packets it's usually the better option. But it seems Smackbilly has no say in the protocol so it's moot anyway.

Lots of games using UDP with a very thin reliable layer on top of it. It can be tweaked to better match their traffic patterns (small packets, no bulk transfers, compensation for loss at the application layer) than TCP.


vvvvvvvv Considering the subject, your analogy should be reversed :v:

haveblue fucked around with this message at 05:26 on May 26, 2008

more falafel please
Feb 26, 2005

forums poster

HB posted:

Lots of games using UDP with a very thin reliable layer on top of it. It can be tweaked to better match their traffic patterns (small packets, no bulk transfers, compensation for loss at the application layer) than TCP.

TCP is way, way, way overkill for most applications. For most applications, it doesn't matter, because the hit you take for using TCP isn't big enough to worry about. There are some applications, games being one of them, where most of the time, you want to reduce bandwidth as much as possible and not waste processing time in the OS doing more checking than you need. Also, many network protocols are not stream-oriented, which leads to building a "message" structure analogous to the underlying packet structure inside the TCP stream, which is in turn on top of the packet structure.

I don't have any idea if a reliable UDP layer is the right tool for Smackbilly's protocol, but he apparently has no control over it. But it's not "emulating TCP" any more than an RDBMS is "emulating a hash table".

Boz0r
Sep 7, 2006
The Rocketship in action.
I'm trying to write a program that could cause my Windows XP computer to do a BSOD. This is apparently harder than I had imagined. Does anyone have a short code snippet that could do this?

ZorbaTHut posted:

With admin access, or without admin access?

Without admin access it should be impossible. With admin access you could always grab the Driver Development Kit, head to Ring 0, and just clobber random bits of RAM.

With admin access. I'm just trying to kill my dell.

Could you give me a little more in-depth hint? I'm not too hot on C++ yet.

Boz0r fucked around with this message at 14:06 on May 26, 2008

ZorbaTHut
May 5, 2005

wake me when the world is saved

Boz0r posted:

I'm trying to write a program that could cause my Windows XP computer to do a BSOD. This is apparently harder than I had imagined. Does anyone have a short code snippet that could do this?

With admin access, or without admin access?

Without admin access it should be impossible. With admin access you could always grab the Driver Development Kit, head to Ring 0, and just clobber random bits of RAM.

Standish
May 21, 2001

Boz0r posted:

I'm trying to write a program that could cause my Windows XP computer to do a BSOD. This is apparently harder than I had imagined. Does anyone have a short code snippet that could do this?


With admin access. I'm just trying to kill my dell.

Could you give me a little more in-depth hint? I'm not too hot on C++ yet.
Not a program but http://support.microsoft.com/kb/244139 lets you generate a bluescreen without messing around with device drivers and kernel SDKs.

ColdPie
Jun 9, 2006

HB posted:

vvvvvvvv Considering the subject, your analogy should be reversed :v:

Boz0r posted:

With admin access. I'm just trying to kill my dell.

Could you give me a little more in-depth hint? I'm not too hot on C++ yet.

Please don't futurequote, it makes threads hell to read. :)

6174
Dec 4, 2004
I've got a C program I'm fixing/updating and there are couple constants I can't identify that hopefully someone recognizes.

The program basically is a wrapper around a plain text file before sending it off to a printer. It does things like add page numbers, line numbers, a header saying what file is being printed, etc. The program used to talk straight to a HP LJ 4m+. The network changed a bit and now that printer is accessed by going through an LPD print server (and hence why I'm updating the program). It has a whole bunch of undocumented usage of PCL 5e (HP's Printer Control Language) that I've been deciphering. However the constants in question don't quite look like PCL commands, which is a lot of the reason I'm confused.

The constants are:
code:
#define PRT_ON "\33[5i"
#define PRT_OFF "\33[4i"
They are used only if a variable "do_termprt" is set, which is in turn set by the command line flag T.

The minimal documentation about -T is "do print through terminal to laserjet".

The other weird thing is PRT_ON is printed before job control commands (ie simplex/duplex and orientation PCL commands) and PRT_OFF is printed immediately following the job control commands and before the contents of the file that is being processed.

I don't think these are PCL commands because PCL commands start with ESC (hex 0x1B, octal 033, decimal 27). However other PCL commands were declared using \033, so I can't rule out that these were typos and should have had an extra 0 to make them octal constants. But I haven't run across any PCL commands that use a [ and PCL commands terminate by a capital letter, which "i" is not. (Keep in mind I hardly knew what PCL was a few hours ago, so I can't say authoritatively that they are not PCL commands)

Does anyone recognize what those constants do?

Vanadium
Jan 8, 2005

They look like those ANSI escapes used to get colored text on terminals. :shobon:

6174
Dec 4, 2004

Vanadium posted:

They look like those ANSI escapes used to get colored text on terminals. :shobon:

I think you've got it. According to here those commands do:

quote:

Stop Print Log <ESC>[4i
* Disable log.

Start Print Log <ESC>[5i
* Start log; all received text is echoed to a printer.

Now this does mean that the program didn't correctly function earlier since the constant would need to be \033, not \33, but it clearly is almost the intended behavior of the original programmer. (The order of PRT_ON and PRT_OFF also need to be switched in the code to suppress the job control commands, which I believe is the intended behavior)

This also explains why it was hard to find these commands in PCL references.

TSDK
Nov 24, 2003

I got a wooden uploading this one

6174 posted:

Now this does mean that the program didn't correctly function earlier since the constant would need to be \033, not \33,
Nope, the '33' is taken to be octal. You can only specify numeric escape sequences as either octal or hexadecimal.

I've started looking at '\0' in a whole new light since I found out it's a second-class octal zero and not a good and proper decimal zero.

6174
Dec 4, 2004

TSDK posted:

Nope, the '33' is taken to be octal. You can only specify numeric escape sequences as either octal or hexadecimal.

I've started looking at '\0' in a whole new light since I found out it's a second-class octal zero and not a good and proper decimal zero.

Interesting. I guess I was too quick to assume the old guy made a mistake. I'm just too used to weird bugs or weird practices in his code. Like that C program I was working on yesterday was in K&R C, despite being up updated every couple years (though it was started in 1990, so being K&R C isn't too odd).

Staggy
Mar 20, 2008

Said little bitch, you can't fuck with me if you wanted to
These expensive
These is red bottoms
These is bloody shoes


Hi, I'm having some problems with linker errors when compiling a small test program. I'm using C++, with SDL, and whenever I try to use a vector I get the error

quote:

Main.obj : error LNK2001: unresolved external symbol __imp___CrtDbgReportW
C:\Documents and Settings\Dan\My Documents\Visual Studio 2008\Projects\SDL_Game\Debug\SDL_Game.exe : fatal error LNK1120: 1 unresolved externals
When i say 'use', I mean that

quote:

vector <int> i_vec;
is okay, but

quote:

vector <int> i_vec;
i_vec.push_back(12);
is not.
SDL on it's own is fine, and vectors on their own are fine, but the two don't seem to want to mix.

I'm using Visual C++ 2008 Express Edition, and I've seen various 'solutions' to this problem. However, they are all way over my head, and I can't work out what I'm supposed to be changing to solve it. Some talk about different library versions, and 'Debug vs. Release' settings, but I have no idea what these amount to.

Can anyone help? I can provide project settings on request.

I apologise for the low-level of the problem.

JoeNotCharles
Mar 3, 2005

Yet beyond each tree there are only more trees.

Staggy posted:

Can anyone help? I can provide project settings on request.

Yes, please do that.

The base problem is that, when compiled in "Debug" mode (which contains lots of extra debug info, so it's slow and bloated but lets you use the debugger) Visual Studio adds extra error checking and stats gathering behind the scenes in its vectors (so vector<T>::push_back calls CrtDbgReportW as well as doing all its regular work). For some reason you're compiling in debug mode but not linking to the version of the library that contains the extra debug report functions.

schnarf
Jun 1, 2002
I WIN.

Staggy posted:

Hi, I'm having some problems with linker errors when compiling a small test program. I'm using C++, with SDL, and whenever I try to use a vector I get the error

When i say 'use', I mean that

is okay, but

is not.
SDL on it's own is fine, and vectors on their own are fine, but the two don't seem to want to mix.

I'm using Visual C++ 2008 Express Edition, and I've seen various 'solutions' to this problem. However, they are all way over my head, and I can't work out what I'm supposed to be changing to solve it. Some talk about different library versions, and 'Debug vs. Release' settings, but I have no idea what these amount to.

Can anyone help? I can provide project settings on request.

I apologise for the low-level of the problem.
Can you describe more about the different files you have, where the SDL code is and where your code is, etc?

Staggy
Mar 20, 2008

Said little bitch, you can't fuck with me if you wanted to
These expensive
These is red bottoms
These is bloody shoes


C++->Code Generation->RunTime Library: Multi-threaded DLL
Linker->Input->Additional Dependencies: SDL.lib SDLmain.lib sdlgfx.lib
Linker->Debugging->Generate Debug info: Yes

Those are the settings that ring a bell, if there's anything specific, or some way for me to post the settings file, please just ask.

EDIT:

http://www.filefactory.com/file/f6f853/

That's the source code so far, but as far as I understand this is more of a settings problem than a code problem. (?)

Staggy fucked around with this message at 22:31 on May 29, 2008

JoeNotCharles
Mar 3, 2005

Yet beyond each tree there are only more trees.
I believe you need to change "Multi-threaded DLL" to "Multi-threaded debug DLL". Although it may do that for you, in which case I'll have to reboot to Windows and look closer.

Staggy
Mar 20, 2008

Said little bitch, you can't fuck with me if you wanted to
These expensive
These is red bottoms
These is bloody shoes


With that change the errors change to

quote:

Linking...
MSVCRTD.lib(cinitexe.obj) : warning LNK4098: defaultlib 'msvcrt.lib' conflicts with use of other libs; use /NODEFAULTLIB:library
Embedding manifest...
mt.exe : general error c101008a: Failed to save the updated manifest to the file ".\Debug\SDL_Game.exe.embed.manifest". The parameter is incorrect.

JoeNotCharles
Mar 3, 2005

Yet beyond each tree there are only more trees.
Ok, sanity check:

This is the Debug profile, right? So everything should be debug. If you're building in the Release profile, you need to do the opposite: put it back to just "Multi-threaded DLL" and then turn "Generate Debug Info" off.

Also, go to C++->Code Generation and make sure that, if it's the Debug profile, the DEBUG symbol is defined and NDEBUG is not, and vice versa if it's the Release profile.

Insurrectum
Nov 1, 2005

Does anyone have some good "first project" introductory programs that someone first starting C++ could cut their teeth on? I took an introductory CSE course at my school (Java) and I'm familiar with the basic concepts of OOP but I'm still trying to understand the way you do things in C++. I'm not interested in learning an "easier" language: I've been turned down several physics internships because they needed C++ programming experience, so I want to learn C++. All I've done so far is write a program that determines if a number is prime or not/prints out a list of primes from one number to another and I've done a few Euler challenges but nothing that hard.

I've read through all of these C++ tutorials and I've done some of their examples. Something along the lines of these projects for Java.

Also, some more general questions:

When should you use cout as opposed to printf? And scanf as opposed to cin?
When you use std::function is that just calling the function in std without having to put "using namespace std;" at the top?

Smackbilly
Jan 3, 2001
What kind of a name is Pizza Organ! anyway?

Insurrectum posted:

When should you use cout as opposed to printf? And scanf as opposed to cin?

Always and never, respectively. There's no reason to use C I/O functions in C++ when there are C++ I/O functions that do everything the C functions do.

quote:

When you use std::function is that just calling the function in std without having to put "using namespace std;" at the top?

Yes. The :: is the scope-resolution operator. You know how when you declare a local variable in a function that variable is not accesible outside the function, so you can re-use the name in other places? Namespaces work kind of the same way, except that you can explicitly refer to a variable inside a namespace from outside that namespace by using namespace::variable. For example, cout is a variable inside the std namespace.

"using namespace std;" means "import ALL of the variable names from the std namespace into the current namespace". You can of course refer to any variable in the current namespace without ::, so this allows you to write cout instead of std::cout. (Note that if you have not declared a namespace, you are working in a default unnamed namespace, which is usually fine)

In some respects "using namespace" is poor style because you're polluting your current namespace with lots of variables that you may not really need. You can be more restrictive by writing "using std::cout;" and "using std::endl;", etc, to import specific variables from another namespace.

If you are familiar with Java, "using namespace foo" is like "import foo.*" and "using foo::bar" is like "import foo.bar". However unlike Java, namespaces are not necessarily associated with a class (although every class is also a namespace).

Smackbilly fucked around with this message at 00:44 on May 30, 2008

Insurrectum
Nov 1, 2005

Smackbilly posted:

Always and never, respectively. There's no reason to use C I/O functions in C++ when there are C++ I/O functions that do everything the C functions do.


Yes. The :: is the scope-resolution operator. You know how when you declare a local variable in a function that variable is not accesible outside the function, so you can re-use the name in other places? Namespaces work kind of the same way, except that you can explicitly refer to a variable inside a namespace from outside that namespace by using namespace::variable. For example, cout is a variable inside the std namespace.

"using namespace std;" means "import ALL of the variable names from the std namespace into the current namespace". You can of course refer to any variable in the current namespace without ::, so this allows you to write cout instead of std::cout. (Note that if you have not declared a namespace, you are working in a default unnamed namespace, which is usually fine)

In some respects "using namespace" is poor style because you're polluting your current namespace with lots of variables that you may not really need. You can be more restrictive by writing "using std::cout;" and "using std::endl;", etc, to import specific variables from another namespace.

If you are familiar with Java, "using namespace foo" is like "import foo.*" and "using foo::bar" is like "import foo.bar". However unlike Java, namespaces are not necessarily associated with a class (although every class is also a namespace).

Alright, those things make a bit more sense now. Thanks!

ehnus
Apr 16, 2003

Now you're thinking with portals!

Smackbilly posted:

Always and never, respectively. There's no reason to use C I/O functions in C++ when there are C++ I/O functions that do everything the C functions do.

One big reason to avoid C++ I/O functions is that they add an implicit dependency on exception handling mechanisms which isn't always an acceptable option.

Smackbilly posted:

In some respects "using namespace" is poor style because you're polluting your current namespace with lots of variables that you may not really need. You can be more restrictive by writing "using std::cout;" and "using std::endl;", etc, to import specific variables from another namespace.

In practice there's nothing wrong with "using namespace ...", in fact as someone who used to work in QA I greatly encourage people to use it because seeing fully qualified names littered throughout code is ugly as sin and in an individual translation unit there's no real danger regarding namespace pollution. The exception to this is in public header files -- people who import namespaces in public headers need to be shot.

Smackbilly
Jan 3, 2001
What kind of a name is Pizza Organ! anyway?

ehnus posted:

One big reason to avoid C++ I/O functions is that they add an implicit dependency on exception handling mechanisms which isn't always an acceptable option.

Okay but if you're eschewing all forms of exceptions, then you're also tossing out STL and basically working in C-with-classes. I suppose some people do that, though.

quote:

In practice there's nothing wrong with "using namespace ...", in fact as someone who used to work in QA I greatly encourage people to use it because seeing fully qualified names littered throughout code is ugly as sin and in an individual translation unit there's no real danger regarding namespace pollution. The exception to this is in public header files -- people who import namespaces in public headers need to be shot.

I wasn't advocating using fully qualified names, I was advocating the middle ground of using "using" statements that specify exactly which symbols you wish to import.

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.

ehnus posted:

One big reason to avoid C++ I/O functions is that they add an implicit dependency on exception handling mechanisms which isn't always an acceptable option.
That's not a big reason for any beginner.

floWenoL
Oct 23, 2002

Smackbilly posted:

Okay but if you're eschewing all forms of exceptions, then you're also tossing out STL and basically working in C-with-classes. I suppose some people do that, though.

What are you talking about? The STL throws exceptions in only a few places.

floWenoL
Oct 23, 2002

Smackbilly posted:

Always and never, respectively. There's no reason to use C I/O functions in C++ when there are C++ I/O functions that do everything the C functions do.

Except the C++ I/O functions are much more verbose and heavyweight. Also, good luck using C++ I/O for binary I/O.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
Basically, I/O streams is poo poo. It's, by far, the worst aspect of the C++ standard libraries, and my greatest wish is to see them replaced with a halfway decent I/O library in the next-next standard.

ehnus
Apr 16, 2003

Now you're thinking with portals!

Mustach posted:

That's not a big reason for any beginner.

I didn't see the "for the beginner" qualification in the post I was responding to, just a blanket qualification that there's no reason to ever choose standard C I/O over C++ I/O.

Smackbilly posted:

Okay but if you're eschewing all forms of exceptions, then you're also tossing out STL and basically working in C-with-classes. I suppose some people do that, though.

A language isn't its standard library.

floWenoL posted:

Except the C++ I/O functions are much more verbose and heavyweight. Also, good luck using C++ I/O for binary I/O.

Yeah, they're not that intuitive. Compare

code:
printf("%08x\n", 0xc0ffee);
to

code:
cout.fill('0');
cout.width(8);
cout << hex << 0xc0ffee << endl;
Which isn't really that intuitive. Why do I set the fill character with cout.fill() but hex formatting by passing in that "hex" value? Why can't I do something like

code:
 cout <<< fill('0') << width(8) << hex << 0xc0ffee << endl; 


instead? Why do I manually have to remember and reset the fill and width parameters for the next field I want to output?

Needless complexity bugs me and the C++ standard library unfortunately is full of it (vector<bool>, I'm looking at you).

Vanadium
Jan 8, 2005

ehnus posted:

Why can't I do something like
cout <<< fill('0') << width(8) << hex << 0xc0ffee << endl;
instead?

Because they are called setfill and setw respectively.

quote:

Why do I manually have to remember and reset the fill and width parameters for the next field I want to output?
No argument there, you have to do it with printf too.

Personally I find a set of member functions or iostream manipulators to define formatting much more intuitive than a formatting "DSL" that is interpreted by *printf at runtime. We all hate DSLs, no?

iostreams are also probably more flexible than having to generate format strings at runtime, if you want more dynamic formatted output, and of course printf cannot be used to print user-defined types.

Is there any existing alternative to iostreams that could be incorporated into the next standard?

Adbot
ADBOT LOVES YOU

Staggy
Mar 20, 2008

Said little bitch, you can't fuck with me if you wanted to
These expensive
These is red bottoms
These is bloody shoes


JoeNotCharles posted:

Ok, sanity check:

This is the Debug profile, right? So everything should be debug. If you're building in the Release profile, you need to do the opposite: put it back to just "Multi-threaded DLL" and then turn "Generate Debug Info" off.

Also, go to C++->Code Generation and make sure that, if it's the Debug profile, the DEBUG symbol is defined and NDEBUG is not, and vice versa if it's the Release profile.

If I build in Debug I get that error, but if I switch to Release to build I get

quote:

MSVCRT.lib(crtexew.obj) : error LNK2001: unresolved external symbol _WinMain@16
C:\Documents and Settings\Dan\My Documents\Visual Studio 2008\Projects\SDL_Game\Release\SDL_Game.exe : fatal error LNK1120: 1 unresolved externals
which is almost back where I began, just a different external symbol.

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