Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230
[SOLVED]Question on creating variables in C
-
- Posts: 21
- Joined: 2018-09-30 12:46
[SOLVED]Question on creating variables in C
I read in my textbook that while creating variables the length should not be normally more than eight characters(though ANSI standard recognizes the length of 31 characters), since only the first eight characters are treated as significant by many compilers.
The question is Will there be any problem or not if there are two variabled having first eight character same (for eg:- average_length and average_width) when only first eight characters are significant?
The question is Will there be any problem or not if there are two variabled having first eight character same (for eg:- average_length and average_width) when only first eight characters are significant?
Last edited by Grishan Pradhan on 2018-10-03 01:47, edited 2 times in total.
- GarryRicketson
- Posts: 5644
- Joined: 2015-01-20 22:16
- Location: Durango, Mexico
-
- Posts: 21
- Joined: 2018-09-30 12:46
Re: Question on creating variables in C
I wish I could but I am just starting. I am at THEORY part.GarryRicketson wrote:Why not just try it and see, ?
Re: Question on creating variables in C
What textbook are you using? It's been 30 yrs since I did "Intro to C Programming" cs 101 and I don't recall that. Maybe things have changed, but at the time I recall my instructor wanted us to use naming for variable that included abbreviated data type in the name, using short tags on the front, like sz_variable1 or sh_variable, ln_var2, or ptr_somepointer. The names were often pretty long.
I like longer descriptive names, but I guess there are many styles. I think it's important to stay consistent.
I like longer descriptive names, but I guess there are many styles. I think it's important to stay consistent.
resigned by AI ChatGPT
-
- Posts: 21
- Joined: 2018-09-30 12:46
Re: Question on creating variables in C
bw123 wrote:What textbook are you using? It's been 30 yrs since I did "Intro to C Programming" cs 101 and I don't recall that. Maybe things have changed, but at the time I recall my instructor wanted us to use naming for variable that included abbreviated data type in the name, using short tags on the front, like sz_variable1 or sh_variable, ln_var2, or ptr_somepointer. The names were often pretty long.
I like longer descriptive names, but I guess there are many styles. I think it's important to stay consistent.
It's a textbook from a native man(Lecturer) and this question is on the book. And I am asking beacuse the answer is not on the book.
Re: Question on creating variables in C
I think you should obey your instructor to get the best grade? Afterwards, obey the project leader when they tell you to do things differently than the instructor? Develop your own style for your own projects, just stay consistent within each type of project.
resigned by AI ChatGPT
- GarryRicketson
- Posts: 5644
- Joined: 2015-01-20 22:16
- Location: Durango, Mexico
Re: Question on creating variables in C
My question is , Is this a home work assignment ? and you are supposed to figure the answer out on your own ? I suspect it is, I know the answer, but you need to figure it out on your own.The question is Will there be any problem or not if there are two variabled having first eight character same (for eg:- average_length and average_width) when only first eight characters are significant?
The answer might not be in the book, and something else to consider, a "Lecturer", can lecture, and talk about all sorts of theories they dream up, but unless the person puts the "theory" to a real life test, it is just a meaning less theory, and has no effect on what happens in real life, or on a real compiler, Maybe the question is intended to make you do some real research, and try some real code, then you can answer the question, Yes it will cause problems, or No it won't, and back up your answer, with real code, a real example.It's a textbook from a native man(Lecturer) and this question is on the book. And I am asking beacuse the answer is not on the book.
It would then no longer be a theory.
A example , but with qbasic, many argue you should not use 'goto', and in theory it can cause problems, So, should you use 'goto' or not, ? The answer is , to try to avoid it's use, but at times it is needed, 'goto' can be used, but mis used it can cause problems.
Go figure. Use some logic.
"What we expect you have already Done"
==========
Old Website
======================
For the Birds
==================
What Does a Parrot Know About PTSD?
==========
Old Website
======================
For the Birds
==================
What Does a Parrot Know About PTSD?
-
- Posts: 21
- Joined: 2018-09-30 12:46
Re: Question on creating variables in C
GarryRicketson wrote:My question is , Is this a home work assignment ? and you are supposed to figure the answer out on your own ? I suspect it is, I know the answer, but you need to figure it out on your own.The question is Will there be any problem or not if there are two variabled having first eight character same (for eg:- average_length and average_width) when only first eight characters are significant?The answer might not be in the book, and something else to consider, a "Lecturer", can lecture, and talk about all sorts of theories they dream up, but unless the person puts the "theory" to a real life test, it is just a meaning less theory, and has no effect on what happens in real life, or on a real compiler, Maybe the question is intended to make you do some real research, and try some real code, then you can answer the question, Yes it will cause problems, or No it won't, and back up your answer, with real code, a real example.It's a textbook from a native man(Lecturer) and this question is on the book. And I am asking beacuse the answer is not on the book.
It would then no longer be a theory.
A example , but with qbasic, many argue you should not use 'goto', and in theory it can cause problems, So, should you use 'goto' or not, ? The answer is , to try to avoid it's use, but at times it is needed, 'goto' can be used, but mis used it can cause problems.
Go figure. Use some logic.
I found this book online which has the same thing written in it.
BOOK(By: E Balagurusamy):https://books.google.com.np/books?id=3f ... &q&f=false
Page no. 29 Point No. 2
Now it is clear that not only "Lecturer" gave his theory on the book. It is also written in the book by someone who happens to be an recognised engineer.
I found the solution too.
Page No. 30 1st paragraph.
Re: Question on creating variables in C
I think I might use two variables named average_length and average_width, or I might use two functions named get_average_length() and get_average_width() and I would expect all compilers or preprocessors to differentiate between the similar identifiers. I never heard of one that could not, but I wouldn't argue the point.
I can't read the google book, but it loks to be from the early 199.s, was it only 8 character identifiers for variables that would have this problem, or functions and other identifiers like macros? Would it have something to do with a compiler flag for optimized code, or smaller name mangling to save space/memory somehow?
I can't read the google book, but it loks to be from the early 199.s, was it only 8 character identifiers for variables that would have this problem, or functions and other identifiers like macros? Would it have something to do with a compiler flag for optimized code, or smaller name mangling to save space/memory somehow?
resigned by AI ChatGPT
- GarryRicketson
- Posts: 5644
- Joined: 2015-01-20 22:16
- Location: Durango, Mexico
Re: Question on creating variables in C
Well, congratulations, then you probably notice , they key word is "IF",
If the compiler only recognizes the first 8 characters, THEN, the 2 names:
mean the same thing to the compiler.
You can use abbreviations, like "ht" for height, or "avg" for average. Or, maybe use a different compiler, one that does recognize longer names.
===== edit =======
Just a thought, more "theory", but I am inclined to agree with the author, or if it is the OP asking :
A long time ago, I got really aggravated , trying to compile code written by windows users, even though it was supposed to be usable and compile able for Linux, the problem was the way windows programmers mix uppercase and lower case, I suppose that is another topic though. But, that is something else that should be avoided when writing code, and naming files,libraries, etc.
If the compiler only recognizes the first 8 characters, THEN, the 2 names:
Code: Select all
average_height
average_weight
You can use abbreviations, like "ht" for height, or "avg" for average. Or, maybe use a different compiler, one that does recognize longer names.
"many compilers" is not the same as all compilers, which is why I said you would need to try it, and see if your compiler accepted it. OR if you looked at the manual for the particular compiler, it might say on that. But yes, the Logic is, you do need to obey and restrictions or limitations the compiler has. So IF it can not recognize a variable name longer then 8 characters. then you must use something shorter or a abbreviation.I read in my textbook that while creating variables the length should not be normally more than eight characters(though ANSI standard recognizes the length of 31 characters), since only the first eight characters are treated as significant by many compilers.
I remember as well , when Dos would not accept filenames over 8 characters , and yes this was the way it was, back in the early and mid 90's , even late 90's. I don't know when this book was written though.bw123 »I can't read the google book, but it loks to be from the early 199.s, was it only 8 character identifiers for variables that would have this problem, or functions and other identifiers like macros?
===== edit =======
Just a thought, more "theory", but I am inclined to agree with the author, or if it is the OP asking :
If one was/is writing source code, it would be best practice to take into consideration that you don't know what compiler might be used by someone else trying to compile the code, so yes there could be problems for those using a compiler that only recognizes 8 characters, in the variables, best practice would be to avoid that.The question is Will there be any problem or not if there are two variabled having first eight character same (for eg:- average_length and average_width) when only first eight characters are significant?
A long time ago, I got really aggravated , trying to compile code written by windows users, even though it was supposed to be usable and compile able for Linux, the problem was the way windows programmers mix uppercase and lower case, I suppose that is another topic though. But, that is something else that should be avoided when writing code, and naming files,libraries, etc.
"What we expect you have already Done"
==========
Old Website
======================
For the Birds
==================
What Does a Parrot Know About PTSD?
==========
Old Website
======================
For the Birds
==================
What Does a Parrot Know About PTSD?
-
- Posts: 21
- Joined: 2018-09-30 12:46
Re: Question on creating variables in C
Thank You.GarryRicketson wrote:Well, congratulations, then you probably notice , they key word is "IF",
If the compiler only recognizes the first 8 characters, THEN, the 2 names:mean the same thing to the compiler.Code: Select all
average_height average_weight
You can use abbreviations, like "ht" for height, or "avg" for average. Or, maybe use a different compiler, one that does recognize longer names."many compilers" is not the same as all compilers, which is why I said you would need to try it, and see if your compiler accepted it. OR if you looked at the manual for the particular compiler, it might say on that. But yes, the Logic is, you do need to obey and restrictions or limitations the compiler has. So IF it can not recognize a variable name longer then 8 characters. then you must use something shorter or a abbreviation.I read in my textbook that while creating variables the length should not be normally more than eight characters(though ANSI standard recognizes the length of 31 characters), since only the first eight characters are treated as significant by many compilers.
I remember as well , when Dos would not accept filenames over 8 characters , and yes this was the way it was, back in the early and mid 90's , even late 90's. I don't know when this book was written though.bw123 »I can't read the google book, but it loks to be from the early 199.s, was it only 8 character identifiers for variables that would have this problem, or functions and other identifiers like macros?
===== edit =======
Just a thought, more "theory", but I am inclined to agree with the author, or if it is the OP asking :If one was/is writing source code, it would be best practice to take into consideration that you don't know what compiler might be used by someone else trying to compile the code, so yes there could be problems for those using a compiler that only recognizes 8 characters, in the variables, best practice would be to avoid that.The question is Will there be any problem or not if there are two variabled having first eight character same (for eg:- average_length and average_width) when only first eight characters are significant?
A long time ago, I got really aggravated , trying to compile code written by windows users, even though it was supposed to be usable and compile able for Linux, the problem was the way windows programmers mix uppercase and lower case, I suppose that is another topic though. But, that is something else that should be avoided when writing code, and naming files,libraries, etc.