I really loved Kochan's C book; it's a fantastic resource and getting it made some major improvements to my skills and understanding. I wish he'd written one for C++, since in the short term that's the language I've decided to go with, but I'll keep ObjC in mind for the future.
Not really true. A statement like
a = malloc(10*sizeof(*a));
is good code and makes sense in C, but won't work in C++. The code that will work in C++, such as,
a = (int *)malloc(10*sizeof(int));
is problematic from a C point of view, because the cast prevents the C compiler from...
Belated thanks for the useful replies. And yes, I know it's normal floating point behaviour. I'm just interested in tracing when numerical methods diverge. :-)
Sure. I know the principle, I was just wondering if there was any advice on how to trace exactly where such an error comes in.
My impression was that the error was occurring in the event of something like this happening:
x += a;
x -= a;
Where a is of much greater order than x (e.g. a...
I'm wondering if anyone can give any advice on tracing a rounding error in a program.
I have two slightly different implementations of a process, which basically come down to the following.
In Version 1, various increments are added to a double variable, and at the end I check to see if it is...
Well, C++ doesn't like malloc() statements much, unless they're cast. :-(
With C I compile with the flags -ansi -pedantic -Wall, so, the strictest C89 compatibility (I believe?).
Regarding your suggestion for the extern "C" { problem, I think I'll still have the same annoying unwanted...
Hi Dian,
Thanks for the thoughts. For what it's worth, I am talking about having very large numbers, so little savings are often important.
In the case of this particular loop, N will not be large; but the whole thing will be contained in a bigger loop that will go round on the order of 100...
Does anyone have any comments on which of these pieces of code will run more efficiently?
In these code examples, check is a variable of type bool (it is an actual variable, not an expression that is reevaluated each time the if() statement is run), and i and N are unsigned ints.
if(check) {...
I've started introducing some C++ modules to my code project (scientific number-crunching), where it's convenient to do so, and have been following the instructions at http://www.parashift.com/c++-faq-lite/mixing-c-and-cpp.html for mixing code.
A few things are niggling me, mostly trivial, but...
Good point. Does ObjC have an ANSI standard? I recall that C++ does.
As for portability, I'm unlikely to be using my code on any systems where gcc will not run.
Am I just being thick here or...
... well, if I understand you right, the second argument is a pointer to the value you wish to write, or read to. So if x is the variable whose value you wish to pass, you would write,
status = EEPROM_IO(0,&x,(unsigned int)EEPROM_SIZE,CLEAR);
... right? So...
I've already fallen for that one, or rather, thought it up, found it didn't work and quickly realised why (it doesn't work for the same reason that sizeof(*a) does work, right?).
Almost invariably when I'm dealing with arrays, they are malloc'd pointers, so this isn't a solution. I guess...
Is there a maximum array length in C, other than the size of the computer's memory?
... and ... are there any functions in the standard library which might tell you the length of an array (other than strlen(), which I know about)?
Great. In that case I'm tempted to go with ObjC since it's a strict superset of C, meaning C code can be cut-and-paste without any worries. I'm thinking of code like this:
{
int *a, *b, *c;
a = malloc(5*sizeof(*a));
b = malloc(5*sizeof(*b));
c = malloc(5*sizeof(*c));
}
...
Thanks for the suggestions. :-)
I have to say that employment isn't really an issue here since I don't make a living from programming. The main thing for me is what might be preferable from a number-crunching speed point of view.
Hello all,
For my code work up until now (scientific number-crunching) I have used C, but there are a handful of cases where it would be useful to have some object-oriented programming (e.g. for simulation of traders bidding on a stock market, or similar multi-agent work).
I've dealt with this...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.