ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Indeed. I made that change. I spent the day doing a few other calculators as well. Also learned to how to include another .c file so I've got a mylibs.c started which 3 of my little programs currently include. Just one function at the moment. I've managed to build these other ones with zero output from
Code:
gcc -Wall -O1 -o $file $file.c
That one eludes me though, the original calc.c. It just tosses a single issue that I just cannot sort out. It works, more of a notification from that gcc command than anything I guess. Worked on that one quite a bit today trying to isolate it.
Indeed. I made that change. I spent the day doing a few other calculators as well. Also learned to how to include another .c file so I've got a mylibs.c
FYI, it's usually a bad idea to include .c files. Typically only .h files are included. For multiple .c files, you would usually compile each of them to .o files which are then linked together. This means that if you change only one .c file, you don't have to recompile the others. You can use a Makefile to manage that.
Quote:
That one eludes me though, the original calc.c. It just tosses a single issue that I just cannot sort out. It works, more of a notification from that gcc command than anything I guess. Worked on that one quite a bit today trying to isolate it.
Ah, I guess gcc doesn't do the inference you expect there. Anyway, I think the best way is to add a default: case into the switch statement, since again with a separate if you end up with two lists of legal operators (and also, gcc won't be confused about it).
I found it. i'm not sure it's what you suggested, may be. I found somewhere that setting a variable inside braces keeps it in those braces, at least as far as the compiler output. It worked but it wasn't perfect. I've since simplified my calcs down to a single one that does float. I made a solution_check function and just call it after setting the solution in each operation instead of once for the entire function. Not a peep from
I can accept this use of "exit(1)" because this is an exception. The program cannot complete and produce an answer. Therefore it exits, returning a "nonzero return code" as a well-understood indication that "something went wrong."
Last edited by sundialsvcs; 01-11-2023 at 03:20 PM.
I can accept this use of "exit(1)" because this is an exception. The program cannot complete and produce an answer. Therefore it exits, returning a "nonzero return code" as a well-understood indication that "something went wrong."
in this case yes, in a real program you need to do some cleanup (for example). But that is another topic.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.