|
To reduce the burden on the generic Programming Questions thread (and to increase the chance that people will actually answer questions), here is the C/C++ Programming Questions thread! I will assume you all know how these threads work: ask questions, or answer them. 'nuff said. Feel free to submit useful links for the OP, I'll try to maintain them. I want to start programming, is C (or C++) a good starting language? C++ might be a little much to learn for someone just starting out, but even so, the language you start with doesn't matter. If you have a specific project in mind that requires C/C++, by all means use it, but don't feel that you need to start with a particular language in order to get the "most" out of learning. However, if you intend to learn both C and C++, it may be best to start with C, since C++ is designed to build on C, and most of the knowledge from C transfers to C++ (but not necessarily vice-versa). gently caress! I'm on Windows and my program works fine for me, but no one else can run it! Deployment on Windows is a bitch. With multiple versions of the C runtime library, debug DLLs, redistributables, and more, chances are you're not going to get it to work on your first try. The following links (thanks to Mustach) should at least point you in the right direction: Visual C++ Deployment How to redistribute the Visual C++ Libraries with your application Useful Guides: (thanks in part to That Turkey Story) The C++ Standards Committee C++ FAQ Lite SGI's STL documentation Thinking in C++ The C++ Source Overview of Generic Programming Exception Safety Libraries: Boost GLib GUI Libraries: (thanks Professor Science!) Windows API GTK Qt wxWidgets Good Books: The C Programming Language by Kernighan and Ritchie The C++ Programming Language by Bjarne Stroustrup Accelerated C++ by Andrew Koenig and Barbara E. Moo Other recommended C++ books Avenging Dentist fucked around with this message at 05:58 on Dec 12, 2009 |
# ¿ Feb 16, 2008 01:14 |
|
|
# ¿ May 4, 2024 06:25 |
|
Milde posted:This post outlines this problem. Lack of partial template specialization for functions pisses me off so much. I needed it for a project, and ended up writing wrappers to do it (though I ultimately changed my design a little to avoid it). Maybe I should clean up my wrappers somewhat and submit them to Boost.
|
# ¿ Feb 18, 2008 20:40 |
|
Captain Frigate posted:I'm pretty new to C and I am wondering what the actual difference is between putchar/getchar and printf/scanf. Is there any? They are the exact opposites of each other. putchar and printf are for output, getchar and scanf are for input.
|
# ¿ Feb 22, 2008 20:32 |
|
This is less a question and more a comment, but I discovered the following "feature" in typedefs today (don't ask how):code:
|
# ¿ Feb 28, 2008 06:01 |
|
JoeNotCharles posted:Why the hell would it compile? x is a sub::bar, which is the same as a base::foo, so it doesn't have a b member. Only sub::foo, which is a completely unrelated struct, has a b member. Well yes, that's the point. The example is greatly simplified; the original involved a complicated chain of template instantiations and was non-obvious, especially since it broke in a completely separate area (the typedef'd template was instantiated with base::foo and all subsequent references to that template, typedef'd or not, used that instantiation). Most of it is kinda obvious in retrospect, but template metaprogramming has a tendency to make obvious things not-so-obvious. EDIT: I am sure it doesn't help that I have been unable to concentrate on anything for the last couple months. Avenging Dentist fucked around with this message at 06:38 on Feb 28, 2008 |
# ¿ Feb 28, 2008 06:34 |
|
That Turkey Story posted:Are you saying that the base class was dependent on a template argument of the child? Not exactly, though I should probably update Cygwin and run my stuff through gcc at some point. A more complete example of my problem would be: code:
|
# ¿ Feb 28, 2008 17:29 |
|
very posted:I've been driving myself nuts for a few days just trying to set up a simple callback. I think I need some Barney-level help. I have two questions: You can't specialize 0 of the template parameters, so it's not a specialization at all. (i.e. remove <Class, ReturnType>) very posted:
Make a base class for GUIButtonCallback to inherit from and use virtual functions. That is, code:
|
# ¿ Mar 2, 2008 02:56 |
|
Thug Bonnet posted:On the other hand, seeking to the next newline and realloc()-ing the buffer for every line seems costly. You'd only need to realloc when the next line is longer than the current one. If you pick a decent starting buffer length, there shouldn't be much reallocation.
|
# ¿ Mar 2, 2008 22:11 |
|
Just use std::size_t. I'm not 100% sure what you're worried about, but size_t is perfectly acceptable, and it's not like the STL avoids it because they were too lazy to add another template argument.
|
# ¿ Mar 5, 2008 01:06 |
|
Lexical Unit posted:Contrived example ahoy! In that example, you'd want to use T::size_type. For merely counting the number of elements, (like .size() in STL containers), you'd use size_t. It's just a question of what exactly you want to measure. EDIT: if you need both, you could have size_type and contained_size_type typedefs.
|
# ¿ Mar 5, 2008 02:08 |
|
cronio posted:Not having the cast there is a compile error in C++ -- is that not true in C? This is one of the important differences between C and C++. In C, void* can automatically be converted to any pointer type.
|
# ¿ Mar 5, 2008 06:50 |
|
Jesus dude, that is some serious table breaking. Also it looks like you're trying to define your template member functions in a separate compilation unit (.cpp file). C++ doesn't allow that. You need to define them in the header.
|
# ¿ Mar 9, 2008 21:52 |
|
floWenoL posted:What is this "typing-time"? It's the pre-preprocessing state, of course!
|
# ¿ Mar 16, 2008 06:04 |
|
code:
|
# ¿ Mar 18, 2008 06:18 |
|
very posted:But I don't see it getting casted to CompoundPrimitiveManager * anywhere. Maybe I should stick a cast in and recompile the library? Unless you're dealing with multiple inheritance, you shouldn't need to worry about casting.
|
# ¿ Mar 18, 2008 19:09 |
|
§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.
|
# ¿ Mar 19, 2008 21:29 |
|
Hopefully, in C++0x, there will just be an "iterator" concept. The more I think about concepts, the more I like them.
|
# ¿ Mar 24, 2008 00:54 |
|
"a.out" is an actual application. It's the default name in gcc for an executable if you don't specify one. By "double click and open a little window", are you referring to a terminal (command line) window, or an actual GUI window? In the case of the former, what you have should already work. In the latter, you'll need to start learning a GUI API (no easy feat). Which API you pick depends on which platform(s) you want to develop for. EDIT: the OP now has a list of GUI libraries, shamelessly stolen from Professor Science's reply on the first page. Avenging Dentist fucked around with this message at 22:52 on Mar 24, 2008 |
# ¿ Mar 24, 2008 22:46 |
|
As long as you're using a cross-platform API, the amount of rewriting you need to do should be minimal. wxWidgets, for instance, uses native controls and supports a wide variety of operating systems.
|
# ¿ Mar 25, 2008 02:09 |
|
BraggPxnk posted:I have heard a lot about how Java is a lot like C++ and I always considered learning it. They have a lot of syntactical similarities, and to a total beginner, they're pretty similar, but when you start getting into more advanced things, they can be very different, especially in terms of design philosophy.
|
# ¿ Mar 25, 2008 03:52 |
|
CasualCliffy posted:but according to the standard, you cannot declare a template parameter to be a friend. I don't see anything in the standard that says this, except that default template parameters can't be used in friend template declarations.
|
# ¿ Mar 25, 2008 17:05 |
|
That Turkey Story posted:If you really want this, put the implementation of your class into a private base, then, from inside Foo, pass off that base to T so that it may access the implementation. It looks like Comeau will let you do something like what he wanted with C++0x extensions on. Did the standard change in this regard?
|
# ¿ Mar 25, 2008 20:08 |
|
Lexical Unit posted:Do you think it would be better to just leave out all the conditional compiling and just flatly require boost? Just require Boost. Speaking of, have you been following the Trie discussion on the Boost developers list?
|
# ¿ Mar 26, 2008 01:09 |
|
Be warned, you'll be inundated with mail unless you check your mail everyday. The Boost developer's list is incredibly busy. I should set up some more filters for it.
|
# ¿ Mar 26, 2008 05:18 |
|
Plastic Jesus posted:I came across this a year or two ago: That is possibly the stupidest thing I've read this year. Are you sure he wasn't trolling?
|
# ¿ Mar 26, 2008 23:56 |
|
Plastic Jesus posted:Yes, Rob Pike is an idiot. Just because he's a famous programmer doesn't mean that he's right. Besides, like people have said, compilers are quite a bit smarter than they used to be, and the performance difference should be negligible (especially compared to template instantiation ), while the maintenance difference is huge.
|
# ¿ Mar 27, 2008 16:40 |
|
Is there something wrong with doing this?code:
|
# ¿ Apr 4, 2008 00:24 |
|
Is there a way to truncate a stream at a certain offset? That is, suppose I have a file open and want to delete a line of text and shorten a file by so many bytes. I can shift the subsequent lines of text with no problem, but there'll be extra space at the end, which kind of defeats the purpose in this case.
|
# ¿ Apr 6, 2008 02:53 |
|
It's pretty much essential that this work with stream objects, since the only guarantee I have is that the stream is open for writing, and supports random access. Nine times out of ten, it'll be a file, but it's entirely possible that the file will be run through a Boost.Iostreams filter like gzip.
|
# ¿ Apr 6, 2008 03:07 |
|
You can use objects in templates, that's the point. You're trying to call insertFront with a reference as the parameter and not a pointer. The types need to match up.
|
# ¿ Apr 13, 2008 02:10 |
|
Don't bother with casts, just do fwrite("\n",1,1,fd);
|
# ¿ Apr 14, 2008 17:56 |
|
Oh, I forgot to mention, another option would be to use fputc('\n',fd); if you're only writing single characters.
|
# ¿ Apr 14, 2008 18:22 |
|
Even if it did work, wouldn't you end up indirectly specializing base::x instead of making a specialized version just for derived::x? Also, I'm pretty sure explicit specializations aren't allowed inside a class. The following is probably closer to what you want (compiles under GCC, Comeau, and VC++2005): code:
|
# ¿ Apr 14, 2008 20:43 |
|
lhunc posted:Another C newb question, this time regarding the passing of structures to functions. If you're doing pure C, you need either struct note in place of note, or the following: code:
|
# ¿ Apr 14, 2008 22:25 |
|
Could you just post your code on https://www.pastebin.com or something?
|
# ¿ Apr 14, 2008 22:38 |
|
operand is a single character and should be a char*. I'm not sure why you're using atof to parse a single character though... Also, you aren't allocating any memory for *number. EDIT: haha
|
# ¿ Apr 15, 2008 21:35 |
|
Er, does that even compile?
|
# ¿ Apr 22, 2008 22:06 |
|
Bender: "... and I thought I saw a two!" Fry: "It was just a dream, Bender! There's no such thing as two."
|
# ¿ Apr 24, 2008 07:06 |
|
Zombywuf posted:For some reason it seems CObject is not EqualityComparable, except privately. That's the assignment operator, but the rest of your post still stands.
|
# ¿ Apr 24, 2008 16:07 |
|
|
# ¿ May 4, 2024 06:25 |
|
Have you looked at Boost.GIL (Generic Image Library for C++)? http://www.boost.org/doc/libs/1_35_0/libs/gil/doc/index.html
|
# ¿ Apr 28, 2008 19:57 |