mersenneforum.org

mersenneforum.org (https://www.mersenneforum.org/index.php)
-   Programming (https://www.mersenneforum.org/forumdisplay.php?f=29)
-   -   C or C++? (https://www.mersenneforum.org/showthread.php?t=16448)

Dubslow 2012-02-27 06:31

I would like to continue, however being a new week, I need to get back to my actual homework, including that "Photoscoop". Let's see how much C I can get done in the process.

As for the loops, one is for reading in characters, and one is so that we can cycle between reading characters and expanding the array... I guess there's got to be a way to simplify it, but 5 minutes of quick thinking isn't shedding too much light on the situation yet. I don't think I want any more hints for now -- but it'll probably be a couple of days before I'll be able to put serious work into this.

jyb 2012-02-27 19:51

[QUOTE=Dubslow;290978]Argh. This might have to take precedence, but I'll try and put some work into C over the week.
[QUOTE]
....
Honor students: Complete the [COLOR="Red"]stenography[/COLOR] class to find and display the secret picture hidden in some of the given image files.
[/QUOTE]
[/QUOTE]

Hilarious!

Dubslow 2012-03-02 04:13

Hehe, whoever wrote ecm.c in Prime95 uses gotos for OutOfMemory exits :smile:

I have a different version of ReadLine in my head, but haven't actually written it yet :P Will probably do so within the next few days

retina 2012-03-02 04:44

[QUOTE=Dubslow;291509]Hehe, whoever wrote ecm.c in Prime95 uses gotos for OutOfMemory exits :smile:[/QUOTE]Nothing wrong with gotos. A perfectly good thing to have and use. Seriously, I'm not being sarcastic. I don't buy into the nonsense about gotos being evil/bad/ruin your day/cause the world to end.

[url]http://xkcd.com/292/[/url]

cheesehead 2012-03-02 04:44

[QUOTE=Dubslow;291509]Hehe, whoever wrote ecm.c in Prime95 uses gotos for OutOfMemory exits :smile:
[/QUOTE]What do you recommend as an improvement?

LaurV 2012-03-02 05:16

[QUOTE=cheesehead;291519]What do you recommend as an improvement?[/QUOTE]
throwing exceptions :P:P

Dubslow 2012-03-02 05:18

I'm not saying it's wrong, I'm just saying... I am writing a ReadLine function that used goto's as my exit statements, in almost exactly the same way as is done in many places in ecm.c . jyb was saying I can make the function better, and without any gotos... I'm not sure how to do that, but then again I haven't put much thought into it (yet).

jyb 2012-03-02 08:19

[QUOTE=Dubslow;291523]I'm not saying it's wrong, I'm just saying... I am writing a ReadLine function that used goto's as my exit statements, in almost exactly the same way as is done in many places in ecm.c . jyb was saying I can make the function better, and without any gotos... I'm not sure how to do that, but then again I haven't put much thought into it (yet).[/QUOTE]

Yes, but to be clear, I wasn't suggesting that it could be better just because it didn't need gotos. The function can be made simpler, clearer and shorter, and as an aside, upon doing that I think you will find that you don't need/want gotos.

FWIW, I think gotos are a perfectly legitimate tool, and that like most tools of any use they can be abused. They are perhaps distinguished by having the ability to screw up code far worse and in far less space than most constructs. I.e. they should be used with care.

ldesnogu 2012-03-02 10:09

[QUOTE=LaurV;291522]throwing exceptions :P:P[/QUOTE]
Exceptions are evil: because of the support at run-time they degrade performance even when they are not used :smile:

ewmayer 2012-03-02 19:13

[QUOTE=ldesnogu;291552]Exceptions are evil: because of the support at run-time they degrade performance even when they are not used :smile:[/QUOTE]

FWIW, I think [strike]gotos[/strike] exception-handlers are a perfectly legitimate tool, and that like most tools of any use they can be abused.

rogue 2012-03-02 20:52

[QUOTE=jyb;291541]FWIW, I think gotos are a perfectly legitimate tool, and that like most tools of any use they can be abused. They are perhaps distinguished by having the ability to screw up code far worse and in far less space than most constructs. I.e. they should be used with care.[/QUOTE]

One of the product groups in my company mandates the use of gotos because they want all functions to have a single return statement.

Then again, they didn't support C99 until two years ago. Try convincing a bunch of 40- and 50-somethings that C99 isn't evil incarnate. For them K&R C is the bible and C++ is a four letter word.

Don't get me wrong, C is a great language, but so is C++. The one you choose is dependent upon what you need to do with it. If you care about performance and memory use above all else (like many of the apps we use for factoring, sieving, primality testing), then C (or asm) is for you. If your application would benefit from encapsulation, inheritance, and polymorphism (like most business apps), then C++ is for you. Most apps would benefit from a combination of both and fortunate for us, then can be used together in the same application.


All times are UTC. The time now is 21:46.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.