|
Is the Ansi C Programming Language a good book to learn C from if you're familiar with the basics of programming, or are there better books to start with?
|
# ? Feb 20, 2008 07:01 |
|
|
# ? May 6, 2024 03:17 |
|
fret logic posted:Is the Ansi C Programming Language a good book to learn C from if you're familiar with the basics of programming, or are there better books to start with?
|
# ? Feb 20, 2008 07:04 |
|
Professor Science posted:is this Kernighan and Ritchie? K&R is *the* book Yes, but is the one I'm talking about the right one? I know the K&R "style" is supposed to come from the first edition, and that the second one is the ansi style. Should I be using the first or second edition?
|
# ? Feb 20, 2008 07:11 |
|
fret logic posted:Yes, but is the one I'm talking about the right one? I know the K&R "style" is supposed to come from the first edition, and that the second one is the ansi style. Should I be using the first or second edition?
|
# ? Feb 20, 2008 07:14 |
|
Professor Science posted:absolutely use the second edition Alright thanks
|
# ? Feb 20, 2008 07:17 |
|
I just started learning a little bit of C in one of my classes, and it's really interesting. I want to learn more of it and eventually maybe start learning C++ after. I totally intend to get the K & R book eventually, but I'm completely broke right now. Is there a really good online C resource for beginners that I can use in the mean time?
|
# ? Feb 21, 2008 01:50 |
|
I'm currently taking an intro to C++ at my uni.... can anyone tell me how to compile and run C++ files on a mac? I've tried using XCode, and it's a bit overwhelming since I'm still new to this...basically, when I write code, compile and build in MS Visual studio, a console window pops up and allows me to test out my program, but the same thing doesnt happen with XCode...nothing pops up.
|
# ? Feb 21, 2008 02:10 |
|
freddy-10eighty posted:I'm currently taking an intro to C++ at my uni.... can anyone tell me how to compile and run C++ files on a mac? I've tried using XCode, and it's a bit overwhelming since I'm still new to this...basically, when I write code, compile and build in MS Visual studio, a console window pops up and allows me to test out my program, but the same thing doesnt happen with XCode...nothing pops up. Open up Terminal.app (in /Applications/Utilities) and use g++ to compile your application. Much simpler than dealing with a huge IDE and hundreds of project settings. And don't forget the -Wall -Wextra switches.
|
# ? Feb 21, 2008 02:24 |
|
GCC's not linking in certain libraries in the C standard library. I can't find any documentation anywhere to help me figure out how to link these in, or force GCC to always link whatever's necessary - any ideas? New Debian installation, GCC 4.1.2.
|
# ? Feb 21, 2008 05:34 |
|
Ari posted:GCC's not linking in certain libraries in the C standard library. I can't find any documentation anywhere to help me figure out how to link these in, or force GCC to always link whatever's necessary - any ideas? The standard library is only a single library, libc, which is always linked in unless you explicitly specify not to. What error are you getting?
|
# ? Feb 21, 2008 05:44 |
|
ShoulderDaemon posted:The standard library is only a single library, libc, which is always linked in unless you explicitly specify not to. What error are you getting? code:
|
# ? Feb 21, 2008 06:32 |
|
Ari posted:This happens whenever I need to reference a function from math.h or stdlib.h - I just gave an example here from math.h. The stdio functions work fine though. Try "-lm".
|
# ? Feb 21, 2008 06:39 |
|
Ari posted:This happens whenever I need to reference a function from math.h or stdlib.h - I just gave an example here from math.h. The stdio functions work fine though. Add -lmath
|
# ? Feb 21, 2008 06:39 |
|
Ari posted:
You can add -lm to the end of the gcc command, which will link in the math library, or if you're on x86 you can add -O which turns on optimizations, including transforming sqrt calls to direct FPU invocation, removing the need for the math library. In the manpage for sqrt(3) you may note the line "Link with -lm.", which specifies which library the function is defined in. Another way to find symbols is "nm -A --defined-only /usr/lib/*.a 2>/dev/null | grep sqrt", which will list all the symbols in all the development libraries you have installed, and search for those that match "sqrt". If a library is called "/usr/lib/libm.a", then you link to it by adding "-lm" at the end of the gcc line.
|
# ? Feb 21, 2008 06:42 |
|
freddy-10eighty posted:I'm currently taking an intro to C++ at my uni.... can anyone tell me how to compile and run C++ files on a mac? I've tried using XCode, and it's a bit overwhelming since I'm still new to this...basically, when I write code, compile and build in MS Visual studio, a console window pops up and allows me to test out my program, but the same thing doesnt happen with XCode...nothing pops up. It's a difference between the way Windows and Unix systems (including OS X) work when it comes to command-line vs GUI apps. If you want to see your program's output, open up Terminal.app (it's in /Applications/Utilities), cd to yourprojectdir/build/(Release or Debug)/yourproject.app/Contents/MacOS and then type ./yourproject to run it. Or, for simple little CLI programs don't bother with a big IDE like Xcode and just run g++ from the command-line. Doc Block fucked around with this message at 11:29 on Feb 21, 2008 |
# ? Feb 21, 2008 09:23 |
|
ShoulderDaemon posted:You can add -lm to the end of the gcc command, which will link in the math library, or if you're on x86 you can add -O which turns on optimizations, including transforming sqrt calls to direct FPU invocation, removing the need for the math library. I bolded the lines that helped to answer my question, thanks. Someone had shown me the "-lm" to link in the math library a couple of days ago, but it didn't help for things that came from stdlib.h, for example the atof function. I didn't know how to find what library to link in to make sure I had coverage for all of my imported functions. Thanks for your help
|
# ? Feb 21, 2008 12:23 |
|
If GCC can find stdlib.h but isn't linking in all the functions from the C standard library then something is wrong with your setup. You shouldn't need any extra command-line options to get the stuff in stdlib.h to work.
|
# ? Feb 21, 2008 15:59 |
|
Ari posted:GCC's not linking in certain libraries in the C standard library. I can't find any documentation anywhere to help me figure out how to link these in, or force GCC to always link whatever's necessary - any ideas? You may or may not have it, but "apt-get install build-essential" will solve a lot of problems. You probably already have it though if your compiler is working.
|
# ? Feb 21, 2008 19:26 |
|
kewlpc posted:It's a difference between the way Windows and Unix systems (including OS X) work when it comes to command-line vs GUI apps. Optionally, since it seems like you are used to working with Visual Studio, and Xcode might be a more friendly environment until you are more comfortable working with the command line (which you should become at some point mind you) stdout goes to Xcode's debug console, which can be access via Cmd-Shift-R. Running a C++ Tool that cout's some stuff will dump it into this window. You can also access it via Run->Console.
|
# ? Feb 21, 2008 19:34 |
|
Let's say that now I want to make my container exception safe. I'm not sure where I can find information on what parts of the STL are exception safe (and at what level). If anyone can recommend a book or website that would help in this area please do. I have Sutter's Exceptional C++, just not on hand at the moment, so if that's good enough just let me know. I can go re-read it now that most of it isn't over my head. In the mean time my immediate quandary involves conceptually reassuring myself that the following is no-throw guarantee exception safe: code:
|
# ? Feb 22, 2008 00:40 |
|
Lexical Unit posted:Let's say that now I want to make my container exception safe. I'm not sure where I can find information on what parts of the STL are exception safe (and at what level). If anyone can recommend a book or website that would help in this area please do. I have Sutter's Exceptional C++, just not on hand at the moment, so if that's good enough just let me know. I can go re-read it now that most of it isn't over my head. From the horse's mouth: http://www.research.att.com/~bs/3rd_safe.pdf
|
# ? Feb 22, 2008 01:38 |
|
Beautiful.
|
# ? Feb 22, 2008 02:31 |
|
I'm pretty new to C and I am wondering what the actual difference is between putchar/getchar and printf/scanf. Is there any?
|
# ? Feb 22, 2008 20:21 |
|
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 |
|
Avenging Dentist posted:They are the exact opposites of each other. putchar and printf are for output, getchar and scanf are for input. That's not quite what I meant. I meant are putchar and getchar (as a pair) functionally different from printf and scanf (as a pair)? What are the functional differences between the I/O pairs?
|
# ? Feb 22, 2008 20:40 |
|
putchar and getchar only do one character at a time and don't do any format conversion. For example: code:
Doc Block fucked around with this message at 20:50 on Feb 22, 2008 |
# ? Feb 22, 2008 20:45 |
|
kewlpc posted:putchar and getchar only do one character at a time and don't do any format conversion. Cool, thanks
|
# ? Feb 22, 2008 21:31 |
|
I haven't touched C++ in a couple of years, so maybe I'm just missing something obvious, but this has me stymied. I have a class I'm using to log events from my app, imaginatively named Log. What I'm trying to do is have a container class (QueueRunner) that monitors and trigger events from a queue, and log those events, failures, etc. I have a constructor in QueueRunner that takes a Log object, and from there, I can write whatever I want to the log: code:
Any subsequent member of the QueueRunner class seems unable to write to the log, however. This code segment doesn't do what I'd expect: code:
Edit: the Log object and the QueueRunner objects are both instantiated in main().
|
# ? Feb 22, 2008 21:35 |
|
You are going to have to post some more code. Could you try reducing it to a testcase?
|
# ? Feb 22, 2008 22:53 |
|
Space Duck posted:I haven't touched C++ in a couple of years, so maybe I'm just missing something obvious, but this has me stymied. Is eventLog of type Log or Log&? If it's Log, does Log's assignment operator work normally, so that if one is copied, the copy has the same log file open? Do you have one QueueRunner object or several?
|
# ? Feb 22, 2008 23:07 |
|
more falafel please posted:Is eventLog of type Log or Log&? If it's Log, does Log's assignment operator work normally, so that if one is copied, the copy has the same log file open? I thought the same thing, but I don't think it can be Log&. If it were the case, wouldn't eventLog -have- to be assigned to log in the constructor's initialization list? I'm leaning towards Log's assignment operator copying the file stream because of that signature (const Log &).
|
# ? Feb 22, 2008 23:12 |
|
Itaipava posted:I thought the same thing, but I don't think it can be Log&. If it were the case, wouldn't eventLog -have- to be assigned to log in the constructor's initialization list? Yeah, you're right about the reference assignment. He should be doing that anyway, though.
|
# ? Feb 22, 2008 23:43 |
|
On Vandanium's suggestion, I've stubbed out a test case. I should have done that first, thanks for the suggestion. Now I'm suspecting that I've mangled something elsewhere, but have ideas of where to look next.code:
code:
quote:Yeah, you're right about the reference assignment. He should be doing that anyway, though. Yeah, I hit on that early on since streams aren't copyable.
|
# ? Feb 23, 2008 02:03 |
|
Is your log class flushing the stream? If you're watching the log file in realtime, waiting for the lines to show up, they might just be buffered (which would happen too in your stubbed test case, except the program ends right after the last call which flushes all the buffers).
|
# ? Feb 23, 2008 06:03 |
|
Does Log's destructor close the stream? I know you said the main Log is instantiated in main(), but is any Log object being destructed at all?
|
# ? Feb 23, 2008 21:14 |
|
fret logic posted:You may or may not have it, but "apt-get install build-essential" will solve a lot of problems. You probably already have it though if your compiler is working. I didn't, and this fixed it entirely. Thanks
|
# ? Feb 24, 2008 21:16 |
|
I was trying to do a easy-to-use observer pattern in C++. I'm kind of new to it.code:
|
# ? Feb 25, 2008 04:07 |
|
Sure, just create all the observers on the stack or in an STL container. Edit: Oops, I got that wrong. Nevermind what it said here before. Vanadium fucked around with this message at 05:17 on Feb 25, 2008 |
# ? Feb 25, 2008 05:13 |
|
Ari posted:I didn't, and this fixed it entirely. Thanks Woohoo, I finally gave something back to CoC Ok guys, I promise this is the last question I'm going to ask about learning before I put my head in a book for a while. I'm learning C and C++ kind of at the same time. So far it's not a big deal since I'm able to differentiate pretty well between the two. I'm using "The C Programming Language" for C, and I just bought this for 7 bucks at a used bookstore: http://www.amazon.com/Problem-Solving-C%2B%2B-Including-Laboratories/dp/0534400051/ref=sr_1_1?ie=UTF8&s=books&qid=1203928841&sr=1-1 I realize there are better books out there, so should I stick with this one or pick one up? The cost doesn't matter much to me, so if I can do a lot better with something else, I'd prefer to. Otherwise, I'll stick with this. What do you guys think?
|
# ? Feb 25, 2008 09:43 |
|
|
# ? May 6, 2024 03:17 |
|
fret logic posted:I'm learning C and C++ kind of at the same time. So far it's not a big deal since I'm able to differentiate pretty well between the two. I'm using "The C Programming Language" for C, and I just bought this for 7 bucks at a used bookstore: The question comes up pretty often as to the de facto library of books for learning various programming languages and concepts. In my experience reading threads discussing them and reading several of the books named, I think the general goon consensus is that Eckel's Thinking in C++ is the best one to pick up C++. But why are you learning both C and C++ at once?
|
# ? Feb 25, 2008 17:55 |