473,714 Members | 2,531 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Additional resources to understand C better.

Hi,
I apologise if this is not the forum for my question.

I am a starter in C and I have come to a point where I can not figure
out if knowledge of assembly language is really essential for an in
depth understanding of C. Also while going through some of the old
posts, essentially as an exercise to understand C better, I read the
following from one Mr. Keith.

"One concrete example is the C implementation on Cray vector machines.
A machine-level address is a 64-bit quantity that points to a 64-bit
machine word, but the C compiler has CHAR_BIT==8, so it needs a
mechanism to point to 8-bit bytes within words. An int* pointer is a
machine address, but a char* or void* pointer has a 3-bit offset
stored in the otherwise unused high-order bits of a word pointer.
This is implemented entirely in code generated by the compiler, not in
hardware. A char* pointer value with a non-zero offset field is a C
address, but it's not a machine address. "

That just flew over the top of my head. :(

What material, books or internet resources, can I read and / or code to
understand that stuff.

The problem with not knowing a thing and trying to learn is that one
does not know how much one does not know. So if you can point me to
additional material or topics that you feel one should know, please do
point me to it.

Thanks in advance.

IC.

Dec 16 '06 #1
8 1413
On 15 Dec 2006 20:26:18 -0800, "In************ @gmail.com"
<In************ @gmail.comwrote in comp.lang.c:
Hi,
I apologise if this is not the forum for my question.

I am a starter in C and I have come to a point where I can not figure
out if knowledge of assembly language is really essential for an in
depth understanding of C. Also while going through some of the old
posts, essentially as an exercise to understand C better, I read the
following from one Mr. Keith.

"One concrete example is the C implementation on Cray vector machines.
A machine-level address is a 64-bit quantity that points to a 64-bit
machine word, but the C compiler has CHAR_BIT==8, so it needs a
mechanism to point to 8-bit bytes within words. An int* pointer is a
machine address, but a char* or void* pointer has a 3-bit offset
stored in the otherwise unused high-order bits of a word pointer.
This is implemented entirely in code generated by the compiler, not in
hardware. A char* pointer value with a non-zero offset field is a C
address, but it's not a machine address. "

That just flew over the top of my head. :(

What material, books or internet resources, can I read and / or code to
understand that stuff.

The problem with not knowing a thing and trying to learn is that one
does not know how much one does not know. So if you can point me to
additional material or topics that you feel one should know, please do
point me to it.

Thanks in advance.
These are the kind of thing that you _never_ need to worry about
writing applications in standard C.

Some programmers take advantage of the "fact" that certain types have
the same size on the particular implementation they happen to be
familiar code. The write code that unnecessarily makes use of this
equivalence of size, then they are surprised when it breaks when
compiler on a different platform, or maybe even a newer version of the
same compiler.

I assume the quotation was in reply to somebody who asserted that all
pointers, or even all pointers to objects, have the same size. That
is true in most C implementations , but not all.

In the case Keith was talking about, the Cray is a computer that is
built for sheer computation speed, what was then called a
"supercomputer" . It was not used for word processing or web browsing,
but was a very, very expensive machine used for intense number
crunching.

To increase speed, it only reads and writes memory in 64-bit words.
Period. All instructions operate on 64-bit integers or 64-bit
floating point values.

But even number crunching programs might need to write their results
to text files that humans can read. To make it easier for programmers
to use plain old ordinary text, the compiler and library implement an
8-bit character type that is not supported by the hardware.

If you want to have 8-bit character types on a computer that can't
address quantities as small as 8 bits, you have two choices.

Choice 1 is to use a whole 64-bit word for each character, storing the
character in the lowest 8 bits and wasting the other 56 bits. But
that can waste a lot of memory.

Choice 2 is to pack up to eight of those 8-bit characters into each
64-bit machine word. But the problem now is how to specify just one
of those characters, when the hardware machine address is the address
of the entire 64-bit word. To do that, you need a field of at least 3
bits somewhere, that can hold eight different values specifying which
of the eight characters in the machine word you want.

So on this platform, a pointer to any of the character types, or a
pointer to void, must have at least three additional bits of
information that a pointer to a 64-bit double, for example, does not
need.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Dec 16 '06 #2

In************@ gmail.com wrote:
Hi,
I apologise if this is not the forum for my question.

I am a starter in C and I have come to a point where I can not figure
out if knowledge of assembly language is really essential for an in
depth understanding of C.
Knowledge of assembly language is required for an in depth
understanding of assembly language.

It is possible (possibly not very useful) to have an in-depth knowledge
of C and have absolutely no knowledge of the machine architecture
you are targetting. Some might argue that this is the best way.

The state you should be aiming for is absolute and in depth knowledge
of C, while noting that many different architectures will implement the
same thing differently (which is why learning by experimentation is
not a Good Thing).
Also while going through some of the old
posts, essentially as an exercise to understand C better, I read the
following from one Mr. Keith.

"One concrete example is the C implementation on Cray vector machines.
A machine-level address is a 64-bit quantity that points to a 64-bit
machine word, but the C compiler has CHAR_BIT==8, so it needs a
mechanism to point to 8-bit bytes within words. An int* pointer is a
machine address, but a char* or void* pointer has a 3-bit offset
stored in the otherwise unused high-order bits of a word pointer.
This is implemented entirely in code generated by the compiler, not in
hardware. A char* pointer value with a non-zero offset field is a C
address, but it's not a machine address. "

That just flew over the top of my head. :(
I wouldn't worry about it, if I were you. Mr Thompson and other
regulars
of this group tend to know all the arcane nooks and crannies of the
C language *in addition* to knowing their target (and other)
implementations
thoroughly.

Be careful not to mix up the two though. For example, if you experiment
on your desktop and find that a long is exactly 32 bits wide, you
cannot
assume that a long in C is 32 bits wide always (a 64 bit platform might
decide to have longs of 64 bits width).

>
What material, books or internet resources, can I read and / or code to
understand that stuff.
Do you *want* to understand that stuff? The reason I ask is because
that stuff will differ from platform to platform.
The problem with not knowing a thing and trying to learn is that one
does not know how much one does not know. So if you can point me to
additional material or topics that you feel one should know, please do
point me to it.
A good start would be the newsgroup for your particular platform.

goose

Dec 16 '06 #3
goose wrote
(in article
<11************ **********@73g2 000cwn.googlegr oups.com>):
It is possible (possibly not very useful) to have an in-depth knowledge
of C and have absolutely no knowledge of the machine architecture
you are targetting. Some might argue that this is the best way.
Depends upon what you actually intend to do down the road, but
in general, yes.
The state you should be aiming for is absolute and in depth knowledge
of C, while noting that many different architectures will implement the
same thing differently (which is why learning by experimentation is
not a Good Thing).
It can be. For example, when you experiment with a single code
base on multiple compilers, operating systems and processor
architectures and see how they work the same or differ. It's
"experiment ing on a single system/compiler" that's prone to bad
habit forming, imo.
--
Randy Howard (2reply remove FOOBAR)
"The power of accurate observation is called cynicism by those
who have not got it." - George Bernard Shaw

Dec 16 '06 #4
Thanks a lot all of you and thanks Mr. Jack, that really helped a lot.

I am mighty confused. I think I understand C fairly well now and am
comfortable with pointers but I do not know "what next". When I say
that, I mean I am overwhelmed by the fact that I should learn about the
calling conventions, as also concepts like implementing OOPS using C,
or perhaps go through the C standards document, from cover to cover. So
I need a little guidance in that direction. Perhaps I am not able to
frame my question in a coherent manner but I am hoping that atleast
some of you must have felt the same during your intial tryst with C and
your experience can throw some light on how can I take the next step.

Thanks once again.

IC

Dec 16 '06 #5

Randy Howard wrote:
goose wrote
(in article
<11************ **********@73g2 000cwn.googlegr oups.com>):
It is possible (possibly not very useful) to have an in-depth knowledge
of C and have absolutely no knowledge of the machine architecture
you are targetting. Some might argue that this is the best way.

Depends upon what you actually intend to do down the road, but
in general, yes.
The state you should be aiming for is absolute and in depth knowledge
of C, while noting that many different architectures will implement the
same thing differently (which is why learning by experimentation is
not a Good Thing).

It can be. For example, when you experiment with a single code
base on multiple compilers, operating systems and processor
architectures and see how they work the same or differ.
That's equally bad; what if all the ones you manage to get
your hands on implement malloc using pages/blocks/whatever
of 32 bytes?

The learner gets the idea that malloc allocates in 32 byte blocks?
The non-learner, OTOH, is presented with no danger in experimenting
to determine what his implementation is doing in order to conform
to the standard.

Experimentation *while learning C* is a bad idea in general. I've seen
too many students who believe that they "know" the number of bits
in an int or that they "know" what happens when they go past the end of
an array "in the C language" merely because they experimented and
found out how all their implementations handle that particular UB.
It's
"experiment ing on a single system/compiler" that's prone to bad
habit forming, imo.
Not only a single system, but many similar systems whose
similarity is not obvious (different compilers for the same platform
may produce the same opcodes for some C code while being
different implementations ).

goose,

Dec 16 '06 #6
goose wrote
(in article
<11************ **********@16g2 000cwy.googlegr oups.com>):
>
Randy Howard wrote:
>goose wrote
(in article
<11*********** ***********@73g 2000cwn.googleg roups.com>):
>>It is possible (possibly not very useful) to have an in-depth knowledge
of C and have absolutely no knowledge of the machine architecture
you are targetting. Some might argue that this is the best way.

Depends upon what you actually intend to do down the road, but
in general, yes.
>>The state you should be aiming for is absolute and in depth knowledge
of C, while noting that many different architectures will implement the
same thing differently (which is why learning by experimentation is
not a Good Thing).

It can be. For example, when you experiment with a single code
base on multiple compilers, operating systems and processor
architecture s and see how they work the same or differ.

That's equally bad; what if all the ones you manage to get
your hands on implement malloc using pages/blocks/whatever
of 32 bytes?
A fair point, but certainly not the "what if" I had in mind.
And also not without being informed, basically, that "all the
world is not a VAX" before they get started. Or in more modern
terms, x86. Add in endian issues, character sets, signed
representations , etc. and pick good variety of targets to
experiment on, and I contend it could have quite the opposite
effect, for a suitably talented student. Given the proper
briefing a good selection in platforms, anybody that still comes
out with nothing but a bunch of misinformed assumptions form
that isn't going to make it to the end of the runway anyway.
The learner gets the idea that malloc allocates in 32 byte blocks?
Whoever said that experimentation must occur in isolation from
other methods and teaching, like good instructors, or good text
books and/or tutorials? You're trying to make a point about
your opinion by carrying it to the point of absurdity through
exaggeration. Sure, there are probably some folks that did
/only/ what you describe without any other forms of learning to
help correct any such bad ideas. I think they are vanishingly
rare in the programmer population though. It was certainly more
likely back when there so many fewer options when it came to
learning materials as compared to today.
The non-learner, OTOH, is presented with no danger in experimenting
to determine what his implementation is doing in order to conform
to the standard.
"The non-learner"? The "non-learner" doesn't learn anything at
all. Do you mean the one that doesn't experiment with actual
compilers, systems and architectures? IMO, you have to be
incredibly uninterested in the topic as a whole to never go down
that path, even a little bit, even when first getting past the
few days with the language when it is explained that C lets you
get closer to the bare metal than other HLLs.
Experimentation *while learning C* is a bad idea in general. I've seen
too many students who believe that they "know" the number of bits
in an int or that they "know" what happens when they go past the end of
an array "in the C language" merely because they experimented and
found out how all their implementations handle that particular UB.
And I'll suspect that of those you have seen, very few of them
experiments on a the kind of "variety" I had in mind when I
wrote the above, or in total isolation from other forms of
learning.
--
Randy Howard (2reply remove FOOBAR)
"The power of accurate observation is called cynicism by those
who have not got it." - George Bernard Shaw

Dec 16 '06 #7
In article <11************ **********@j72g 2000cwa.googleg roups.com>
In************@ gmail.com <In************ @gmail.comwrote :
>What material, books or internet resources, can I read and / or code to
understand that stuff.
You do not *need* to know details about various machine architectures
in order to use the C language. If you *want* to learn such things,
though, your best bet may be a college course on hardware architectures.

(It may also help to learn some background electrical-engineering
principles, although even basic EE courses tend to be much more
intensive than required for understanding simple digital logic.
For instance, there is no need to know about Thevenin and Norton
equivalents, much less analyzing AC circuits and transmission lines,
in order to understand the basic workings of a D or J/K type
flip-flop. Those two -- D and J/K -- are the basis for all other
digital circuits. Of course, transmission line theory can help
explain *why* a digital circuit is misbehaving, but that is another
topic entirely. :-) )

Language courses (runtime organization of languages, compiler
design, and so on) may also be helpful, and possibly operating
systems courses.

There are a lot of textbooks that would go with these (authored
by folks such as Hennesy and Patterson, Silberschatz and/or Peterson,
and so on). Knuth (all volumes) and Sedgewick are good reference
works as well, although they focus more on algorithms and data
structures.
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
Dec 17 '06 #8
<In************ @gmail.comwrote in message
news:11******** **************@ 73g2000cwn.goog legroups.com...
Thanks a lot all of you and thanks Mr. Jack, that really helped a lot.

I am mighty confused. I think I understand C fairly well now and am
comfortable with pointers but I do not know "what next". When I say
that, I mean I am overwhelmed by the fact that I should learn about
the
calling conventions, as also concepts like implementing OOPS using C,
or perhaps go through the C standards document, from cover to cover.
So
I need a little guidance in that direction. Perhaps I am not able to
frame my question in a coherent manner but I am hoping that atleast
some of you must have felt the same during your intial tryst with C
and
your experience can throw some light on how can I take the next step.
The first step is to start working with advanced data structures and
algorithms, such as trees, hash tables, sorts, etc. You also need to
learn how to decide which to use in various cases, and how to
troubleshoot bugs. In fact, learning to use your debugger well is
probably the single most important thing, since that's what you'll spend
most of your time doing when you start writing more complex programs.
Writing new code is a tiny, tiny part of most programmers' lives; the
rest is spent fixing bugs or hacking in the occasional new feature.

Another important step is learning what the Standard guarantees vs. what
your implementation guarantees and/or what what you've found happens to
work while experimenting. There are many things you'll have picked up
assuming they're correct/portable (or not knowing there's a difference);
porting a program from Windows to POSIX or vice versa is an eye-opening
experience to folks who learned on a single platform. You'll find out a
large part of what you "know" is simply wrong.

That's not to say writing unportable code is bad -- but you need to know
when that's what you're doing, and how to account for it, i.e. writing
wrappers so that 90% of the code is portable and all you need to change
when porting is to write a new wrapper. Networking, threads, GUIs,
makefiles, etc. are all good things to learn once you've mastered the
core language -- and learning how incredibly different they are on
various OSes (if they exist at all) will teach you the importance of
knowing what C guarantees vs. what an implementation
provides/guarantees.

After you've gotten past those hurdles, go find an open source project
that intrigues you and simply read the code. Once you understand it
(which, unless it's tiny, will take a while), try adding a new feature.
It doesn't even matter how big it is or if anyone else finds it
useful -- it's the process that you need to learn. Then go look up some
bug reports and try to diagnose/fix one. If you succeed, contribute a
patch.

All that'll keep you busy for months or even years :-)

S

--
Stephen Sprunk "God does not play dice." --Albert Einstein
CCIE #3723 "God is an inveterate gambler, and He throws the
K5SSS dice at every possible opportunity." --Stephen Hawking
--
Posted via a free Usenet account from http://www.teranews.com

Dec 17 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1395
by: Tony Johansson | last post by:
Hello experts!! I reading in a book about C++ and there is something that I'm not sure about. I don't belive that the book is wrong but I will just ask you out there what you think. The book says the following "Note that you cannot assume that all resources are automatically released when the entire program tetminates. While this is true for resources allocated exclusively for
4
40018
by: Rachel Suddeth | last post by:
What is the difference between a managed/unmanaged resource, and how do you tell which is which? I'm trying to understand how to write some Dispose() methods, and we are supposed to put code that deals with managed in one place, and code that deals with unmanaged in another place, but I can't seem to find anything that clearly explains what that means. I think if I used a Windows API function to optain a handle, that handle would be an...
0
1093
by: Jordi Gou | last post by:
Hello. I want to develop an application that let me update a resource of another one. I developed a method to update strings of the string tables resources and to update bitmaps resources. My problem appears with icon resources and I don't understand very well how icons go. I read an article "Icons in Win32" in MSDN, but I don't understand how transform RT_ICON (that we have in .ico file) to RT_GROUP_ICON (that we have
1
1891
by: fabrice | last post by:
Hello, I'm trying to use Resources file to manipulate language in my application Web. I'm using vb.net and framewok 1.1. I have read some articles about the subject. But i don't understand everything ! For the moment, i have created différents .aspx page and associated file ..vb. >> "My application is not compiled yet into .dll."
4
1366
by: David | last post by:
I am using My.Resources (VS2005) to build all messages that my application displays to the user. Often I like to embed a new line character in the middle of the string to make it more readable. Currently I do this by typing a place holder in the string value when I type it into the resource editor (e.g. <NL>), and then when I use the string I replace the place holder like this: MsgBox(My.Resources.SomeCustomMessage.Replace("<NL>",...
25
3016
by: Koliber (js) | last post by:
sorry for my not perfect english i am really f&*ckin angry in this common pattern about dispose: ////////////////////////////////////////////////////////// Public class MyClass:IDisposable
0
1255
by: schaf | last post by:
Hi All! I would like to have additional information (ResourceBuildDate) in the *.resx and afterwards in the *.resources to ensure the right .resources would be used for the satellite assemblies. Adding a new unused string to a custom generated .resx is easy, but it would be a problem for forms.resx files because these files will be generated by the system and so I will lost my entry. So I though I could use the resheader and add there a...
2
1468
by: schaf | last post by:
Hi NG ! I would like to add additional information to a .resources file. For instance the translation date, How can I add this information to the .resources file of a form? In the resheader, the information will be deleted during the generation of the .resources (using resgen). Is there a possibility to add additional information to a .resourcee file? Thanks and Regards
8
8998
by: Varangian | last post by:
Hello, was wondering of how to dispose of managed resources? or referencing every member of a class to null will release resources...? http://www.marcclifton.com/tabid/79/Default.aspx http://www.codeproject.com/managedcpp/garbage_collection.asp - sources
0
8704
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9307
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9170
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9071
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9009
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6627
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4462
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4715
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2105
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.