Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Learning C as an existing programmer

Reply
Thread Tools

Learning C as an existing programmer

 
 
Rui Maciel
Guest
Posts: n/a
 
      06-25-2012
Jorgen Grahn wrote:

> Over at comp.lang.c++ they say it's C++.


I'm also over at comp.lang.c++, and I've also spent a bit of time developing
number-crunching applications with C++. If this discussion was hosted in
that newsgroup I would still underline the merits of Fortran, C and
Matlab/Octave.


Rui Maciel
 
Reply With Quote
 
 
 
 
Ben Bacarisse
Guest
Posts: n/a
 
      06-25-2012
gwowen <(E-Mail Removed)> writes:

> On Jun 25, 11:50Â*am, Ben Bacarisse <(E-Mail Removed)> wrote:
>
>> > 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.

>
> 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.


Yes, really, but there are several of parts to the answer.

First, I accept that there are systems where you can't rely on them, but
I'd expect more from a modern system. I can set a stack size if the
default is too small (I can even set it to "unlimited") and I get a
run-time error if my arrays are too large.

Secondly, your characterisation of the size is, err... provocative. All
arrays (malloced or otherwise) are of bounded size so (i) is a red
herring. To say that they can only be what you consider trivially small
does not matter if trivially small is big enough. The phrase you use,
however, is clearly designed to suggest that they are pointless but
that's not been my (limited) experience.

Thirdly, C99's variably modified arrays are useful even if you don't
give all (or some) of your arrays automatic storage. The ability they
offer to specify the size of dimensions other than the "last" can be
very helpful.

--
Ben.
 
Reply With Quote
 
 
 
 
Rui Maciel
Guest
Posts: n/a
 
      06-25-2012
David Brown wrote:

> So that's a "yes" in answer to my first question?


No, the rest, as I've said, is just noise. Fanboyism only leads people to
look at every problem as being a nail to try to justify using their
particular brand of hammer.


Rui Maciel
 
Reply With Quote
 
Rui Maciel
Guest
Posts: n/a
 
      06-25-2012
David Brown wrote:

> So that's a "yes" in answer to my first question?


No, the rest, as I've said, is just noise. Fanboyism only leads people to
look at every problem as being a nail to try to justify using their
particular brand of hammer.


Rui Maciel
 
Reply With Quote
 
Nachy
Guest
Posts: n/a
 
      06-25-2012
On Jun 24, 6:26*pm, Ian Collins <(E-Mail Removed)> wrote:
> On 06/25/12 09:52 AM, rammy wrote:
>
> > 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 wasGW
> > 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.


I actually took a similar path myself - well, not quite: QBasic ->
8086 Assembly -> C (-> C++) -> Java (the latter is job-related; the
others were hobbies...).

I found that the best book for C is still "The C Programming Language"
- despite its age - as has been pointed out. As for moving between
BASIC and C - I don't know what book will be best, and any that I've
seen are more than 20 years old. However, I thought of a few pointers
to help cover the major differences:

1) C code is not line oriented.
- Multiple statements may be on the same line
- A statement can be broken into several lines
- Statements are ended with a semicolon (';') instead of a line break
- Blocks are delimited by braces ('{' and '}'), instead of END at the
bottom

2) case matters.
- "if" is not the same as "If" or "IF"
- Nearly everything in C is lowercase - keywords and the standard
library.
_Exit() is the only exception I can think of.
- Constants are UPPERCASE (as in many languages, including BASIC)
- Identifiers with several words use under_scores, not CamelCase

3) Strings are not first-class types.
- String literals are given some special treatment by the compiler,
but ...
- Strings break down into NUL terminated arrays of char

- String concatenation is not automatic

3) Many tasks are accomplished by library functions instead of being
statements built in to the language.
- This includes basic input, output, file operations, and mathematical
functions
- Use puts() instead of PRINT, printf() instead of PRINT USING,
scanf() instead of INPUT
- Any user-friendly GUI is non-standard (as far as C is concerned).
There are libraries other than the C standard library available for
various platforms, each of which has its own standards.

4) You have to put a lot more effort into memory management.
- malloc() instead of DIM (whatever that stands for)
- Pointers are used much more heavily than in BASIC (which has some
pointer ability)

That's all that I can think of offhand, but I think that's plenty.

Happy programming!

-- Nachy

 
Reply With Quote
 
Edward Rutherford
Guest
Posts: n/a
 
      06-25-2012
Charles Richmond wrote:
> "Ian Collins" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> On 06/25/12 09:52 AM, rammy wrote:
>>> 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".

> 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.


Any Basic programmer understands pointers! A pointer is basically the
same thing as a ByRef function argument.

The only exception is strings, which are a special type in C. For
technical reasons they are officially pointers (char *) but in fact this
is really just the string type, so char ** is a ByRef string.
 
Reply With Quote
 
Stefan Ram
Guest
Posts: n/a
 
      06-25-2012
Nachy <(E-Mail Removed)> writes:
>- Statements are ended with a semicolon (';') instead of a line break


»{}« is a statement that does not end with a semicolon.
(Use »expression statement« above.)

>- Constants are UPPERCASE (as in many languages, including BASIC)


Uppercase is used for most preprocessor macros,
which might sometimes expand to literals.

>- String concatenation is not automatic


Well, »"abc" "def"« gives »abcdef«.

 
Reply With Quote
 
James Kuyper
Guest
Posts: n/a
 
      06-25-2012
On 06/25/2012 04:37 PM, Edward Rutherford wrote:
....
> Any Basic programmer understands pointers! A pointer is basically the
> same thing as a ByRef function argument.
>
> The only exception is strings, which are a special type in C. For
> technical reasons they are officially pointers (char *) but in fact this
> is really just the string type, so char ** is a ByRef string.


It's been more than three decade since I used Basic, and I'm pretty sure
that the Basic I used didn't have ByRef, so I can't comment on that
aspect of your message.

However, in C, strings are a data storage format, not a data type.
Saying otherwise can cause more confusion than is justified by the
simplification it allows. Thinking otherwise has been the cause of a lot
of erroneous code.
 
Reply With Quote
 
James Kuyper
Guest
Posts: n/a
 
      06-25-2012
On 06/25/2012 04:26 PM, Nachy wrote:
....
> - despite its age - as has been pointed out. As for moving between
> BASIC and C - I don't know what book will be best, and any that I've
> seen are more than 20 years old. However, I thought of a few pointers
> to help cover the major differences:

....
> - Nearly everything in C is lowercase - keywords and the standard
> library.
> _Exit() is the only exception I can think of.


There are few more exceptions that than. If most of these seem
unfamiliar, that's probably because they were all introduced in either
C99 or C2011:

keywords:
_Alignas, _Alignof, _Atomic, _Bool, _Complex, _Generic, _Imaginary,
_Noreturn, _Static_assert, _Thread_local

Standard Pragmas:
STDC FENV_ACCESS
STDC FP_CONTRACT
STDC CX_LIMITED_RANGE

Function-like macros:
CMPLX, CMPLXF, CMPLXL
ATOMIC_VAR_INIT
[U]INT[N|MAX]_C
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      06-25-2012
Edward Rutherford <(E-Mail Removed)> writes:
[...]
> Any Basic programmer understands pointers! A pointer is basically the
> same thing as a ByRef function argument.
>
> The only exception is strings, which are a special type in C. For
> technical reasons they are officially pointers (char *) but in fact this
> is really just the string type, so char ** is a ByRef string.


No, strings are not pointers.

A string is, by definition, "a contiguous sequence of characters
terminated by and including the first null character".

A char* value that points to the first character of a string is referred
to as a "pointer to a string".

We commonly (actually, almost universally) use pointers of type char* to
manipulate strings, but the pointer itself is not the string.

--
Keith Thompson (The_Other_Keith) http://www.velocityreviews.com/forums/(E-Mail Removed) <http://www.ghoti.net/~kst>
Will write code for food.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Urgent positions: Sr Programmer Analyst (SPA) and Programmer Analyst(PRA)-06+month's- Carson City, NV. Isaac Java 0 12-08-2010 05:34 PM
Who gets higher salary a Java Programmer or a C++ Programmer? Sanny Java 391 01-06-2010 02:48 AM
Who gets higher salary a Java Programmer or a C++ Programmer? Sanny C++ 396 12-17-2008 06:13 PM
Existing Dll - using Functions from an existing dll Tristin.Colby@gmail.com Ruby 0 02-05-2008 07:38 PM
Why no existing Java type to existing XML schema binding support? nrm Java 3 04-10-2006 04:52 PM



Advertisments