[Tutorial] Introduction to programming using C
Forum rules
Forum rule Nº 15 is strictly enforced in this subforum.
Forum rule Nº 15 is strictly enforced in this subforum.
Re: [Tutorial] Introduction to programming using C (I)
No, it's not relative. "Levelness" is always relative to machine code.
Advertising
I wanna lots of mov al,0xb
"just not into this RA stuffz"
"just not into this RA stuffz"
Re: [Tutorial] Introduction to programming using C (I)
C (compiled) is not lower-level than LUA (scripted) ?
Advertising
That is not Unix. That is OSX a proprietary branch of BSD.
-
- Retired Mod
- Posts: 805
- Joined: Mon Sep 27, 2010 6:55 pm
Re: [Tutorial] Introduction to programming using C (I)
if you are implying that scripting languages are higher level programming languages than compiled languages, then that is not necessarily the case. levelness of a programming language depends on the level of abstraction between said language & machine language. whether its compiled or interpreted has nothing to do with it, but rather how much the language hides the specifics of whats really going on in the machine code is the real determining factor.Terbaddo wrote:C (compiled) is not lower-level than LUA (scripted) ?
if thats not what you're implying, then imho c and lua are on a similar level. to me neither abstracts more than the other, for example printf is not any more abstract to me then screen:print.
Re: [Tutorial] Introduction to programming using C (I)
Yes it is. Let's end this...Terbaddo wrote:C (compiled) is not lower-level than LUA (scripted) ?
I wanna lots of mov al,0xb
"just not into this RA stuffz"
"just not into this RA stuffz"
-
- Posts: 186
- Joined: Thu Jan 20, 2011 1:16 pm
- Location: Milky Way, Solar system, Earth, North America, Canada, Québec..... In front of my computer
Re: [Tutorial] Introduction to programming using C (I)
ultimakillz wrote:if you are implying that scripting languages are higher level programming languages than compiled languages, then that is not necessarily the case. levelness of a programming language depends on the level of abstraction between said language & machine language. whether its compiled or interpreted has nothing to do with it, but rather how much the language hides the specifics of whats really going on in the machine code is the real determining factor.Terbaddo wrote:C (compiled) is not lower-level than LUA (scripted) ?
if thats not what you're implying, then imho c and lua are on a similar level. to me neither abstracts more than the other, for example printf is not any more abstract to me then screen:print.
levelness of a programming language != abstraction level, but more how close the language is with the hardware... normally, a high level language will also need an interpreter, so there is more "thing" between the hardware and the program.
Re: [Tutorial] Introduction to programming using C
I got a teach yourself C++ book the other day because i feel like my mind is dying a bit so please bear in mind i know nothing and i'm starting from first principles.
Take this -
The exercise i'm looking at says "Modify the program you just made to read an int rather than a double. Note that sqrt is not defined for int values so assign n to a double and take sqrt of that.
So expecting it to fail i just changed double to int to see what happened like this -
But that works fine, and when i use 9 as my integer it gives back 3 for a sqrt.
Why's that work ok if int shouldn't work with the sqrt function?
Take this -
Code: Select all
#include "../../../std_lib_facilities.h"
int main()
{
cout << "Please input a floating point value: ";
double n;
cin >> n;
cout << "n == " << n
<< "\nn+1 == " << n+1
<< "\nthree times n == " << 3*n
<< "\ntwice n == " << n+n
<< "\nn squared == " << n*n
<< "\nhalf of n == " << n/2
<< "\nsquare root of n == " << sqrt(n)
<< endl;
keep_window_open();
}
So expecting it to fail i just changed double to int to see what happened like this -
Code: Select all
#include "../../../std_lib_facilities.h"
int main()
{
cout << "Please input a number: ";
int n;
cin >> n;
cout << "n == " << n
<< "\nn+1 == " << n+1
<< "\nthree times n == " << 3*n
<< "\ntwice n == " << n+n
<< "\nn squared == " << n*n
<< "\nhalf of n == " << n/2
<< "\nsquare root of n == " << sqrt(n)
<< endl;
keep_window_open();
}
Why's that work ok if int shouldn't work with the sqrt function?
Re: [Tutorial] Introduction to programming using C
First, this thread is not about C++ but about C. Second, you're asking something totally off-topic for this thread and should have created a new topic to ask that. Third, it's kind of weird mixing C++ and C like you do. If you're going to learn C++, learn it object-oriented. If you don't want to learn object-oriented programming, go with plain C. Mixing those will result in a disaster, specially when learning.
That said, I'll answer you anyway. The compiler is most likely giving you a warning about that (if it doesn't, make sure you're using a recent decent compiler and correct flags are set (-Wall for GCC/G++)). The reason it's working is because the compiler is smart and it automatically converts your int into double before passing it to the sqrt() function, because conversion from int to double is straightforward. Anyway, for sake of readability (and getting rid of the warning) you should explicitly cast that int into double:
That said, I'll answer you anyway. The compiler is most likely giving you a warning about that (if it doesn't, make sure you're using a recent decent compiler and correct flags are set (-Wall for GCC/G++)). The reason it's working is because the compiler is smart and it automatically converts your int into double before passing it to the sqrt() function, because conversion from int to double is straightforward. Anyway, for sake of readability (and getting rid of the warning) you should explicitly cast that int into double:
Code: Select all
<< "\nsquare root of n == " << sqrt( (double) n)
I wanna lots of mov al,0xb
"just not into this RA stuffz"
"just not into this RA stuffz"
Re: [Tutorial] Introduction to programming using C
Sorry, i made a noobish error posting here but didn't want to start a new topic for something trivial.
Regarding your concern over mixing stuff up...i'm working directly from Bjarne Stroustrup's Programming Principles and Practice Using C++, which i figured was a good starter.
So basically putting (double) prior to my integer allows a disallowed function by putting the value into a double read space?
Thanks and sorry i won't do it again.
Regarding your concern over mixing stuff up...i'm working directly from Bjarne Stroustrup's Programming Principles and Practice Using C++, which i figured was a good starter.
So basically putting (double) prior to my integer allows a disallowed function by putting the value into a double read space?
Thanks and sorry i won't do it again.
Re: [Tutorial] Introduction to programming using C
Never read it, but it depends to whom that book is intented and what's your programming background.xist wrote:i'm working directly from Bjarne Stroustrup's Programming Principles and Practice Using C++, which i figured was a good starter.
Yes, that's called casting. But beware with that because compiler will only convert the data format correctly (double format is not int format) if he knows how to. Otherwise the data format will remain the same, but compiler won't raise any error (unlike Java for example where unknown castings are not allowed).xist wrote:So basically putting (double) prior to my integer allows a disallowed function by putting the value into a double read space?
I wanna lots of mov al,0xb
"just not into this RA stuffz"
"just not into this RA stuffz"
Re: [Tutorial] Introduction to programming using C
Thank you. I'll start a new topic in future.
As for the book, it's a beginners book and i know nothing....
Thanks again.
(didn't get any errors btw...)
As for the book, it's a beginners book and i know nothing....
Thanks again.
(didn't get any errors btw...)