Learning C as an existing programmer

R

rammy

Hi

I need to learn C for numerical analysis as part of my Masters research.

I already have quite a lot of experience with BASIC (my progression was GW
BASIC -> QBASIC -> Visual BASIC -> VB.net) so I want to find an
introductory book on "C for BASIC programmers".

I looked through the campus bookstore and didn't really find anything.
Can you recommend some learning materials that will leverage my existing
programming knowledge?

Thanks in advance!
 
I

Ian Collins

Hi

I need to learn C for numerical analysis as part of my Masters research.

I already have quite a lot of experience with BASIC (my progression was GW
BASIC -> QBASIC -> Visual BASIC -> VB.net) so I want to find an
introductory book on "C for BASIC programmers".

I looked through the campus bookstore and didn't really find anything.
Can you recommend some learning materials that will leverage my existing
programming knowledge?

"The C Programming Language". C is sufficiently different to justify
reading through the whole book.
 
C

Charles Richmond

Ian Collins said:
"The C Programming Language". C is sufficiently different to justify
reading through the whole book.

To understand C well... you have to understand the way C uses pointers.
Pointers are very basically machine memory addresses, and C uses them in
special ways. IMHO.
 
B

Ben Bacarisse

rammy said:
I need to learn C for numerical analysis as part of my Masters research.

I already have quite a lot of experience with BASIC (my progression was GW
BASIC -> QBASIC -> Visual BASIC -> VB.net) so I want to find an
introductory book on "C for BASIC programmers".

I looked through the campus bookstore and didn't really find anything.
Can you recommend some learning materials that will leverage my existing
programming knowledge?

If your application makes extensive use of arrays or of complex numbers,
you might want to find out if you have access to an implementation of
the 1999 standard of C. Many of the books about C concentrate on 1990 C
(often called, rather confusingly, "ANSI C") but C99 added complex
numbers and some array facilities that might be helpful for numerical
programs.
 
S

Stefan Ram

Charles Richmond said:
To understand C well... you have to understand the way C uses pointers.
Pointers are very basically machine memory addresses, and C uses them in
special ways.

An object o of type T is a region of memory that is just
large enough to store a single value of T.

The address »a« of such an object is written as »&o«
using the unary prefix operator »&« (»address of«).
We say that »&o« »referred« to the object or location o.

The type of »a« is written as »T*«. This is a pointer type.
An object of pointer type can store a value of such a
pointer type.

Given »a«, to get the value of the object »o«, we use »*a«,
with the unary prefix operator »*«. One says that this
»dereferred« »a«.

*&o = o

»&o+1« is the address just behind this object »o«, that
can be obtained by skipping the size of the object »o«
once. »&o+i« are i such skips.

For an int value »i«, »a« means »*(a+i)«.

*a = a[0]
a+i = &a

»T*p;« declares »p to be a pointer to an object of type »T«.

»p=0« makes »p not to point to anything, directly after this
»p« is a »null pointer«. A null pointer cannot be used for
anything else than to mark the absence of a pointer that
refers an object.

Pointers can be compared with »==« and »!=« (even the null
pointer) and be compared with »>« and so on when reasonable.

if(p)statement

for a pointer p is equivalent to

if(p!=0)statement

, the corresponding assertion holds for the ?:-operator and
iteration statements.

»T*const p;« declares a constant pointer (it cannot be
changed after initialisation).

»T const*p;« declares a read-only pointer (it cannot be used
to write to the object whose address it referss).

»T const*const p;« a constant read-only pointer.

A pointer to void has the type »void*«, it cannot be used
with the above pointer operators »*« and »+«, but can be
used where an object of pointer type »T*« is expected
and can also represent a value of any other pointer type.

Explicit pointer type conversions can be done using the
cast operator, but are not recommended for beginners.

There is no portable string representation of pointer
values, but an implementation might print an
implementation-specific representation of a pointer value
when the format specifier »%p« is used with a pointer to
void.

One can only use and derefer pointer values when reasonable,
they need to refer to certain reasonable locations, such as
declared or allocated objects or certain special places
(just behind an array), and one can only derefer pointers
referring a declared or allocated object.

For two pointers »p« and »q«, when reasonable, the
difference »p-q« is defined and has type »ptrdiff_t« of the
»<stddef.h>« header, so that for an array »a« the difference
»&a[j]-&a« has the value »j-i« of this type.

»+« and »-« with pointers are called »address arithmetics«.

The value of a string literal is a pointer referring its
first char, and has type »char const*«.

A pointer to a function represents that function as a
pointer. it cannot be dereferred or used with address
arithmetics or combined with object pointers. When »f«
names a function, »&f« is a pointer to that function and
can be used instead of »f« in calls.
 
J

Joe.

rammy said:
Hi

I need to learn C for numerical analysis as part of my Masters research.

Fucking liar.
I already have quite a lot of experience with BASIC

OK, then NO experience. Noted. One must ask, WTF are they teaching in
"universities"? (been there, done that, don't like 'em).
(my progression was GW
BASIC -> QBASIC -> Visual BASIC -> VB.net) so I want to find an
introductory book on "C for BASIC programmers".

You should forget about programming and get into some labor job or politics
at minimum wage. Thinking is not your forte.
I looked through the campus bookstore

And she rejected you cuz she saw you as the dud you are?
and didn't really find anything.
Disallusionment.

Can you recommend some learning materials that will leverage my existing
programming knowledge?

You don't have any programming knowledge.
Thanks in advance!

**** you beforehand.
 
J

Joe.

Ian Collins said:
"The C Programming Language". C is sufficiently different to justify
reading through the whole book.

You are so aberrated! (I don't spell check).
 
J

Joe.

Charles Richmond said:
To understand C well... you have to understand the way C uses pointers.
Pointers are very basically machine memory addresses, and C uses them in
special ways. IMHO.

Your "humble" opinion is no longer relevant. C and snake oil are related
how? If you can't answer that question, then you are a <something>. It's one
thing to be a "bullshitter", quite another to be a victim of bullshitters.
Or in the "worst" case, bullshit politics. Ha! Are not politics and bullshit
the same thing?

:( BS is casual. Politics hurt, maim and kill people.

Don't everyone think you make me think. Apparently that is Warren Buffet's
job? Apparently he is so fucking "rich" he can't even give away what he did
legally. Hmm? What does an old man with a lot of money have to say?
Rhetorical, cuz we know what he said.

Peace be with you, "rich" man.
 
J

Joe.

Stefan Ram said:
An object o of type T is a region of memory that is just
large enough to store a single value of T.

How does it feel to be a textbook instead of a person?
 
M

Malcolm McLean

בת×ריך ×™×•× ×¨×שון, 24 ביוני 2012 22:52:37 UTC+1, מ×ת rammy:
Hi

I need to learn C for numerical analysis as part of my Masters research.

I already have quite a lot of experience with BASIC (my progression was GW
BASIC -> QBASIC -> Visual BASIC -> VB.net) so I want to find an
introductory book on "C for BASIC programmers".
Everything works in C more or less as you would expect, with a few exceptions.

Types are strict. So a variable must be either a double-precison float, or a single precision float, or an integer, and so on. There's not much intelligent mixing of types.

You declare structures to create compound types,a nd this is used heavily.

Strings are just arrays of chars.

Virtually everything is a function. C itself just does logic. There's no real difference between a built-in fucntiona nd one you write yourself. So there's no print statement, instead you call a function.


Pointers are the heart of C, and the thing that C does rather differently to other languages. Pointers are essentially raw memory addresses, Peek and Poke in old-fashioned Basic. Basically a C program consists of passing about pointers, and reading and writing to them, doing calculations and moving data about in memory.

malloc() is very heavily used. Usually you won't know the length of an array at compile time. So you malloc() a block of memory to use for the array. Also you often use malloc() to create structures like trees and linked lists.
 
R

Rui Maciel

David said:
Do you have to use C? There are other languages that might be a better
choice - Python with SciPy / NumPy comes to mind - then you can
concentrate more on the numerical analysis, and less on the details of
programming.

For numerical analysis, if it's not possible to use Fortran then the next
best option is plain old C.

And numerical analysis boils down to details of programming, as the main
purpose is to squeese as much computational juice out of a computer as
possible. You don't get that by simply toying with algorithms. Hence,
Fortran and C being the standards for real world number crunching
applications.

Even if a user wants to toy around with numerical analyis stuff without
having to look too much under the hood, Python is still not an adequate
option; there is Matlab/Octave for that.


Rui Maciel
 
R

Ronald Benedik

"Rui Maciel" schrieb im Newsbeitrag
David said:
Do you have to use C? There are other languages that might be a better
choice - Python with SciPy / NumPy comes to mind - then you can
concentrate more on the numerical analysis, and less on the details of
programming.
For numerical analysis, if it's not possible to use Fortran then the next
best option is plain old C.

I would not recommend the old version of C, but the C99 Standard instead.
Complex Numbers are important for quantum Physics applications.
Also to mention is the complex eletric current.
And numerical analysis boils down to details of programming, as the main
purpose is to squeese as much computational juice out of a computer as
possible. You don't get that by simply toying with algorithms. Hence,
Fortran and C being the standards for real world number crunching
applications.

Numerical Analysis is not the Analysis of Algorithms.

Next, what difference between Fortran 2008 and C?
New Fortran standards introduce features as operator overloading and
object oriented Programming. C99 does not do that: C++ does the job.
 
R

Rui Maciel

Ronald said:
"Rui Maciel" schrieb im Newsbeitrag




I would not recommend the old version of C, but the C99 Standard instead.
Complex Numbers are important for quantum Physics applications.
Also to mention is the complex eletric current.

The "plain old" bit was only an idiomatic expression (like "good old X", in
contrast with brand spanking new Python). It wasn't a reference to K&R or
any specific standard. But you are right, C99 does offer some nice
features, particularly if complex numbers are required.

Numerical Analysis is not the Analysis of Algorithms.

Who said it was?

Next, what difference between Fortran 2008 and C?
New Fortran standards introduce features as operator overloading and
object oriented Programming. C99 does not do that: C++ does the job.

Why is that relevant? There is quite a lot of fundamental libraries which
are used in this very day that are written with Fortran 77, and don't even
have a Fortran90 version available.


Rui Maciel
 
B

Ben Bacarisse

Malcolm McLean said:
Pointers are the heart of C, and the thing that C does rather
differently to other languages. Pointers are essentially raw memory
addresses, Peek and Poke in old-fashioned Basic.

That's not a helpful thing to say to someone new to C. You don't have
to go into details but C's pointers, crucially, have a type. The type
is used to give a more useful meaning to the operations done on them,
just like the type a variables are used to determine the meaning of
operations like / (integer or floating division). C pointer operations
will be baffling if they are seen as raw addresses.

malloc() is very heavily used. Usually you won't know the length of an
array at compile time. So you malloc() a block of memory to use for
the array.

Unless you can use "modern" C with its flexible arrays. They don't
behave exactly like malloced storage does, but they are often more
appropriate for numerical programs.

<snip>
 
R

Ronald Benedik

"Rui Maciel" schrieb im Newsbeitrag
Why is that relevant? There is quite a lot of fundamental libraries which
are used in this very day that are written with Fortran 77, and don't even
have a Fortran90 version available.

I wanted to give the Basic programmer an idea about Fortran and C
differences.
 
H

Heikki Kallasjoki

Even if a user wants to toy around with numerical analyis stuff without
having to look too much under the hood, Python is still not an adequate
option; there is Matlab/Octave for that.

Python with NumPy/SciPy can be a perfectly adequate option, when
compared to Octave, especially for people with no Matlab background.

Octave might provide a larger amount of functions (especially if
counting the octave-forge package collection), but the NumPy/SciPy API
is by no means barren. (Even if it is a bit messy.)

As far as performance goes, they use largely the same libraries (ATLAS,
LAPACK, ARPACK, FFTW, ...) for heavy lifting, and for the odd loop (that
can't be easily turned into a matrix operation) here and there Octave
can be really very slow. In some random benchmarks NumPy performance
has been somewhere in-between Matlab and Octave for matrix-handling
code, and orders of magnitude better than Octave for "regular" code that
you might also want to have in the same program. (YMMV, as always; the
benchmarks I found weren't especially comprehensive.)
 
G

gwowen

Unless you can use "modern" C with its flexible arrays.  They don't
behave exactly like malloced storage does, but they are often more
appropriate for numerical programs.

Really? Only if they're (i) of bounded size or (ii) of trivially small
size. Otherwise you're just asking for horrible, undetectable stack
overflow bugs, because VLAs have no failure mechanism.
 
R

Rui Maciel

David said:
I take it you have no experience with Python or SciPy, but are merely
prejudice against Python because it is interpreted?
What?


Of course you can
get greater speed with C than with straight Python.

Exactly. The rest is just noise.


Rui Maciel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top