LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-18-2004, 07:22 PM   #1
andzerger
Member
 
Registered: Feb 2004
Location: denver
Distribution: slackware && freeBSD && rh9
Posts: 92

Rep: Reputation: 15
programming, um, fundamentals .. ?


take the C language:

time(*long) returns the amount of seconds that have passed since some date, its declared in time.h .. why? what are the porpuse of header files? they contain practically no code; never any conditional operations, just alot of definitions, structure declarations and some function prototypes often strangely preceded by a few __s, so wheres the actual library? all i want is a boolean clock function that goes 0 .. 1 .. 0 .. 1 like the actul hardware does

yeah okay this line of inquiry probably doesnt make a whole lot of sense, im just trying to get off the high level programming trip before i forget whats really going on in a computer..
 
Old 02-18-2004, 07:31 PM   #2
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
The purpose of the header files is so you can see what functions there are, and what they need as arguments, without having to worry about the implementation getting in the way. I mean, you can assume the glibc functions work, so who cares how the code does it. If you really want to know, download the glibc source.

As far as timers go in hardware... they usually increment a register, and throw an interrupt when it overflows. If all it did was oscillate between 0 and 1 you would have no idea if you missed a cycle or not so it wouldn't be too useful for a timer....
 
Old 02-18-2004, 07:58 PM   #3
andzerger
Member
 
Registered: Feb 2004
Location: denver
Distribution: slackware && freeBSD && rh9
Posts: 92

Original Poster
Rep: Reputation: 15
does the register clear once the interrupt is thrown?
 
Old 02-18-2004, 09:24 PM   #4
infamous41md
Member
 
Registered: Mar 2003
Posts: 804

Rep: Reputation: 30
all things of that nature are entirely implementation dependent. if you want to play with low level stuff learn assembly it's awesome. for example, lets say you want to get a `clock' tick in assembly language. if you're on int x86 pentiums, you can use the `rdtsc' instruction. this reads the contents of the timestamp counter register on the processor. this register is incremented once every clock cycle of the processor. the low 32 bits in eax, and the high 32 go in edx. using the low bits a way to measure small time intervals. on a 500mhz comp it overflows once every 8 seconds. if you want, you can also read the whole 64 bits and that doesnt overflow for a loooong time. if you wanted to do it in C, you could do this:
Code:
#define rdtsc(low,high) \
     __asm__ __volatile__("rdtsc" : "=a" (low), "=d" (high))

#define rdtscl(low) \
     __asm__ __volatile__("rdtsc" : "=a" (low) : : "edx")
and then pass it an unsigned integer arg to read the counter. btw, that is from /usr/src/linux/include/asm-i386/msr.h"
 
Old 02-18-2004, 09:51 PM   #5
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
The timer interrupts on overflow, which would mean it would be cleared to 0 if it represents an unsigned number.
 
Old 02-18-2004, 09:54 PM   #6
SciYro
Senior Member
 
Registered: Oct 2003
Location: hopefully not here
Distribution: Gentoo
Posts: 2,038

Rep: Reputation: 51
the headers are just definitions so the compiler knows what to do with it, the actual libs are usualy in /lib or other places like /usr/lib, these are alrdy been compiled to from there the loader loads the required imformation into memory when the program runs
 
Old 02-19-2004, 12:51 AM   #7
andzerger
Member
 
Registered: Feb 2004
Location: denver
Distribution: slackware && freeBSD && rh9
Posts: 92

Original Poster
Rep: Reputation: 15
ahh beautiful, thank you all. i got a lot of thinking to do

id like to learn assembly, thats what my inquirys all about. i just havent made it to school yet (summer) and am easily confused by some of the terms im finding in the assembly book ive got .. registers for example, now at least i have a better idea about what one is (some piece of hardware that can store a certain amount of electricity, apparantly)

anyway, thanks, now i understand the first few paragraphs of chapter one

-andrew
(software engineering student to become electronics engineering student)
 
Old 02-19-2004, 01:54 AM   #8
bdp
Member
 
Registered: Apr 2002
Distribution: RH 9
Posts: 230

Rep: Reputation: 30
check out the 'what is a shift register?' paragraphs/drawing, hope this ties software and electrical engineering ideas together a bit more...

http://www.doctronics.co.uk/4015.htm
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
which programming language is used to do tcp/ip programming?? gajaykrishnan Linux - Networking 9 12-21-2012 05:16 AM
Another Newbie with more questions about the fundamentals! Alastoros LinuxQuestions.org Member Intro 1 07-10-2005 03:09 PM
Difference between Top Down programming & Bottom up programming minil Programming 1 06-17-2005 02:42 AM
Fundamentals of Printing doctorwebbox Linux - Newbie 3 01-28-2005 02:13 PM
Switching Terminals, Fundamentals B. Alec Slackware 6 02-15-2004 05:02 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration