473,804 Members | 3,311 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Some Questions #2

some other doubts:

1) K&R, p50, 2.10:

"if expr1 and expr2 are expressions, then
expr1 op= expr2
is equivalent to
expr1 = (expr1) op (expr2)
except that expr1 is computed only once."

what does "except that expr1 is computed only once" mean? can you make
any example in which this propriety is important?

2) is it true that the value of a character constant such as 'C' depends
on the system character set (ASCII, EBCDIC, ...)? so if i write
something as 'C' - 20, will my program become not portable?

3) is it true that a char *must* be 1 byte? here instead
http://www-ccs.ucsd.edu/c/types.html...nteger%20Types is written
that the requisite is that the *minimum* range for unsigned char, for
example, must be from 0 to 255, so it may be 2 bytes or 200 bytes
without any problem.

4) i have some problems at distinguish declaration from definitions.

for example:

double function(double x, double y); /* prototype (a kind of function
declaration) */

double function(double x, double y) { /* function definition */

int a; /* definition? declaration? */

}

also, are 'double x, double y' in the function definition two
definitions or two declarations?

thanks.
Apr 14 '06 #1
17 1762
fctk wrote:
some other doubts:

1) K&R, p50, 2.10:

"if expr1 and expr2 are expressions, then
expr1 op= expr2
is equivalent to
expr1 = (expr1) op (expr2)
except that expr1 is computed only once."

what does "except that expr1 is computed only once" mean? can you make
any example in which this propriety is important?
Hard to say. The value of expr1 is computed only once in both cases.
2) is it true that the value of a character constant such as 'C' depends
on the system character set (ASCII, EBCDIC, ...)? so if i write
something as 'C' - 20, will my program become not portable?
Not necessarily. It depends on what you do with the result.
3) is it true that a char *must* be 1 byte? here instead
http://www-ccs.ucsd.edu/c/types.html...nteger%20Types is written
that the requisite is that the *minimum* range for unsigned char, for
example, must be from 0 to 255, so it may be 2 bytes or 200 bytes
without any problem.
Yes. The terms char and byte are generally interchangeable and
'sizeof(char)' is guaranteed 1.
4) i have some problems at distinguish declaration from definitions.

for example:

double function(double x, double y); /* prototype (a kind of function
declaration) */

double function(double x, double y) { /* function definition */

int a; /* definition? declaration? */

} You've got those two right.
also, are 'double x, double y' in the function definition two
definitions or two declarations?
A declaration presents information to the compiler without affecting
memory (storage) at all. Function prototypes are declarations.

A definition is also a declaration (info for the compiler) but it
demands space for itself in memory.
thanks.

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Apr 14 '06 #2


fctk wrote On 04/14/06 13:21,:
some other doubts:

1) K&R, p50, 2.10:

"if expr1 and expr2 are expressions, then
expr1 op= expr2
is equivalent to
expr1 = (expr1) op (expr2)
except that expr1 is computed only once."

what does "except that expr1 is computed only once" mean? can you make
any example in which this propriety is important?
array[ expensive_funct ion(x) ] += 1;

It becomes even more important if the computation doesn't
always return the same answer:

array[ getchar() ] += 1;
2) is it true that the value of a character constant such as 'C' depends
on the system character set (ASCII, EBCDIC, ...)? so if i write
something as 'C' - 20, will my program become not portable?
Yes, it is true that the numeric value of 'C' depends on
the character encoding. Yes, it is true that doing arithmetic
of the kind you've shown produces a result whose meaning will
vary from one implementation to another. (Exception: the codes
for the digits must be consecutive and in ascending order, so
'0'+1 == '1', ..., '8'+1 == '9'. However, 'a'+1 == 'b' is not
guaranteed.)
3) is it true that a char *must* be 1 byte? here instead
http://www-ccs.ucsd.edu/c/types.html...nteger%20Types is written
that the requisite is that the *minimum* range for unsigned char, for
example, must be from 0 to 255, so it may be 2 bytes or 200 bytes
without any problem.
In C, a byte is defined as synonymous with a char. Some
other fields use the term "byte" to mean "a unit of storage
comprising eight bits," but C does not: in C, a byte is a char
no matter how wide a char is.

This is really the same situation that confronts you in
understanding other words: Different realms of discourse use
the same word with different meanings, and you must know the
context to find the proper meaning. For example, consider the
various meanings "file" might have if you're talking about

- how to use the fopen() function

- the formations exhibited by a marching band

- the contents of a metalworker's toolbox

- recipes from a Cajun cookbook (well, the pronunciation
might tip you off about this one)
4) i have some problems at distinguish declaration from definitions.

for example:

double function(double x, double y); /* prototype (a kind of function
declaration) */

double function(double x, double y) { /* function definition */

int a; /* definition? declaration? */

}
A declaration describes the type of object or function
an identifier designates. A definition also brings the
object or function into existence, allocating storage for
objects or providing the executable code for functions.
Every definition is also a declaration, but a declaration
is not necessarily a definition. When I say "fctk is a
student of C" I make a declaration about what "fctk" means;
a definition is more like "fctk is a student of C, and here
he is (smile, fctk, smile and wave)."

A prototype is a description of a function's parameters.
A prototype may appear as part of a function declaration or
as part of a function definition, but the prototype is only
the part about the parameter list. Your first example is a
function declaration using a prototype; your second is a
function definition using a prototype. Neither of them "is"
a prototype in its entirety.
also, are 'double x, double y' in the function definition two
definitions or two declarations?


Formally speaking, they are declarations. Note that some
of the "decoration s" that are possible with definitions are
not possible with function parameters; these are illegal:

double f(static double x, extern double y,
double z = 42.0, typedef double trouble)

Function parameters don't need definitions as such; if you
want, you can think of them as being "defined" as part of
the process of calling the function. Somehow the compiler
causes the parameters to come into existence and be initialized
with the argument values as part of the function invocation,
and somehow the compiler causes them to vanish again when the
function returns. If you are interested in how compilers and
related tools work, the mechanics of this buck-passing are of
importance to you; if you simply need to use C, they are not.

--
Er*********@sun .com

Apr 14 '06 #3
On Fri, 14 Apr 2006 19:21:37 +0200, in comp.lang.c , fctk <-> wrote:
what does "except that expr1 is computed only once" mean? can you make
any example in which this propriety is important?
it would be important if "expr1" changed each time you invoked it, for
example x++
2) is it true that the value of a character constant such as 'C' depends
on the system character set (ASCII, EBCDIC, ...)? so if i write
something as 'C' - 20, will my program become not portable?
Yes.
3) is it true that a char *must* be 1 byte?
Yes. This is the definition of a byte in C.
here instead
http://www-ccs.ucsd.edu/c/types.html...nteger%20Types is written
that the requisite is that the *minimum* range for unsigned char, for
example, must be from 0 to 255, so it may be 2 bytes or 200 bytes
without any problem.
Its true the min range must be 0-255, but this onl defines the minimum
number of bits. A "byte" is defined in C to be as large as the number
of bits in a character, even if that is 8, 9, 32 or 36.
4) i have some problems at distinguish declaration from definitions.
A declaration doesn't define something. If the statement either sets
the value of something, or contains code which will do so, then its a
definition.
also, are 'double x, double y' in the function definition two
definitions or two declarations?


In a declaration, they're neither (since you can leave them out and it
doesn't make any difference).
In a function definition, they're declarations of the parameters.
Mark McIntyre
--
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Apr 14 '06 #4
fctk wrote:

some other doubts:

1) K&R, p50, 2.10:

"if expr1 and expr2 are expressions, then
expr1 op= expr2
is equivalent to
expr1 = (expr1) op (expr2)
except that expr1 is computed only once."

what does "except that expr1 is computed only once" mean? can you make
any example in which this propriety is important?
Consider:

*pt++ += foo;

Or:

*SomeFunctionTh atTakesALongTim e() += bar;

Or:

*NextItemInList () += foobar;
2) is it true that the value of a character constant such as 'C' depends
on the system character set (ASCII, EBCDIC, ...)? so if i write
Correct.
something as 'C' - 20, will my program become not portable?
It depends on what you do with 'C'-20. If you expect it to be '/', then
it won't necessarily work on non-ASCII systems. If there isn't any
particular significance to 'C' and 20, then it may be just fine.

But things like adding 32 to an uppercase letter and expecting to get
the corresponding lowercase letter is definitely non-portable if you
intend to use a non-ASCII system somewhere in the future.
3) is it true that a char *must* be 1 byte? here instead
http://www-ccs.ucsd.edu/c/types.html...nteger%20Types is written
that the requisite is that the *minimum* range for unsigned char, for
example, must be from 0 to 255, so it may be 2 bytes or 200 bytes
without any problem.


Well, "sizeof(cha r)" must be "1". But, if by "byte" you mean "a group
of 8 bits", then the answer to your question is "no", as a char may be
larger than 8 bits.

[...]

--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer .h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <mailto:Th***** ********@gmail. com>
Apr 14 '06 #5
Kenneth Brody <ke******@spamc op.net> writes:
fctk wrote:

[...]
3) is it true that a char *must* be 1 byte? here instead
http://www-ccs.ucsd.edu/c/types.html...nteger%20Types is written
that the requisite is that the *minimum* range for unsigned char, for
example, must be from 0 to 255, so it may be 2 bytes or 200 bytes
without any problem.


Well, "sizeof(cha r)" must be "1". But, if by "byte" you mean "a group
of 8 bits", then the answer to your question is "no", as a char may be
larger than 8 bits.


If by "byte" you mean "a group of 8 bits", you're not using the word
in the way defined by the C standard -- or by historical usage.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Apr 14 '06 #6
Keith Thompson wrote:
Kenneth Brody <ke******@spamc op.net> writes:
fctk wrote:

[...]
3) is it true that a char *must* be 1 byte? here instead
http://www-ccs.ucsd.edu/c/types.html...nteger%20Types is written
that the requisite is that the *minimum* range for unsigned char, for
example, must be from 0 to 255, so it may be 2 bytes or 200 bytes
without any problem.

Well, "sizeof(cha r)" must be "1". But, if by "byte" you mean "a group
of 8 bits", then the answer to your question is "no", as a char may be
larger than 8 bits.


If by "byte" you mean "a group of 8 bits", you're not using the word
in the way defined by the C standard -- or by historical usage.

You are, however, using the word as it's used by the majority of people
today. Not to imply that this gives that usage a privileged status, of course.

S.
Apr 14 '06 #7
On Fri, 14 Apr 2006 19:21:37 +0200, fctk <-> wrote:
some other doubts: snip4) i have some problems at distinguish declaration from definitions.

for example:

double function(double x, double y); /* prototype (a kind of function
declaration) */

double function(double x, double y) { /* function definition */

int a; /* definition? declaration? */

}

also, are 'double x, double y' in the function definition two
definitions or two declarations?

The best memory aid I have seen for distinguishing declarations from
definitions is

Think of definitions as in a dictionary. The book has mass
and occupies space. (It is real.)

Think of declarations as statements by politicians. They do
not guarantee the topic will ever really have a real existence. (They
are ephemeral.)

In C

A definition causes whatever is being defined to actually
exist in your program. If it is an object (variable, array, struct,
etc), then memory is reserved for it. If it is a function, then the
code is incorporated into your program. The existence of a definition
"overrides" any previous or subsequent declarations so you can say
that the definition serves as a declaration also.

A declaration serves only to describe the object or function,
that is its attributes. For example, the declaration
extern int x;
does not define x (memory is not allocated) but it does promise the
compiler that when the program is ready to execute x will be defined
somewhere and will have the correct size and alignment for an int. (It
is the linker's job to figure out how to resolve references to x but
that is a different topic.) Similarly, a function prototype does not
define the function but does promise the compiler that the function
will exist in the program and will take the arguments described and
return the object specified.
Remove del for email
Apr 15 '06 #8
>>3) is it true that a char *must* be 1 byte? here instead
http://www-ccs.ucsd.edu/c/types.html...nteger%20Types is written
that the requisite is that the *minimum* range for unsigned char, for
example, must be from 0 to 255, so it may be 2 bytes or 200 bytes
without any problem.

In C, a byte is defined as synonymous with a char. Some
other fields use the term "byte" to mean "a unit of storage
comprising eight bits," but C does not: in C, a byte is a char
no matter how wide a char is.


ok, in C "byte" and "char" are synonymous. but is it correct that char
does not necessary need to be 8 bits?
4) i have some problems at distinguish declaration from definitions.

for example:

double function(double x, double y); /* prototype (a kind of function
declaration ) */

double function(double x, double y) { /* function definition */

int a; /* definition? declaration? */

} also, are 'double x, double y' in the function definition two
definitions or two declarations?

Formally speaking, they are declarations. Note that some
of the "decoration s" that are possible with definitions are
not possible with function parameters; these are illegal:

double f(static double x, extern double y,
double z = 42.0, typedef double trouble)


why `double x, double y' in

double function(double x, double y) { /* ... */ }

are declarations? yes, they tell the compiler x and y refers to two
object of type double, but also the memory for them is allocated when
the function is called.

pretty as in:

void nothing(void) {
int a; /* definition */
}
Apr 15 '06 #9
fctk <-> said:
ok, in C "byte" and "char" are synonymous.
I think of "byte" as a capacity and "char" as the kind of thing that would
need a capacity in which to be stored. But yes, one char fits precisely
into one byte.
but is it correct that char
does not necessary need to be 8 bits?
Yes. I've used systems where chars need 32 bits (and therefore bytes are 32
bits wide).
why `double x, double y' in

double function(double x, double y) { /* ... */ }

are declarations? yes, they tell the compiler x and y refers to two
object of type double, but also the memory for them is allocated when
the function is called.


They are definitions as well as declarations. All object definitions and
function definitions are also declarations.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Apr 15 '06 #10

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

Similar topics

2
2015
by: Ross Micheals | last post by:
All I have some general .NET questions that I'm looking for some help with. Some of these questions (like the first) are ones that I've seen various conflicting information on, or questions that I'm not sure are specific anomolies that I'm having, or if they are specific known issues I'm facing. 1. In VB.NET, are arrays stored on the stack or the heap? Why must arrays of value types be boxed in order for them to be (effectively) passed by...
12
2335
by: Vibhajha | last post by:
Hi friends, My sister is in great problem , she has this exam of C++ and she is stuck up with some questions, if friends like this group provides some help to her, she will be very grateful. These are some questions:- 7. design and implement a class binsearch for a binary search tree.it includes search,remove and add options.make suitable assumption. 8.explai how pointers to functions can be declared in c++.under what conditions can...
1
1817
by: Tony Johansson | last post by:
Hello Experts! I have some questions about inheritance that I want to have an answer to. It says "Abstract superclasses define a behavioral pattern without specifying the implementation" I know that an abstract class doesn't have any implementaion even if a default implementatiion can be supplied for pure virtual methods. What does it actually mean with saying that an Abstract superclasses define a behavioral pattern?
162
14934
by: techievasant | last post by:
hello everyone, Iam vasant from India.. I have a test+interview on C /C++ in the coming month so plz help me by giving some resources of FAQS, interview questions, tracky questions, multiple choice questions.etc.. I'll be indebted to everyone.. Thanks in advance.. regards vasant shetty Bangalore
50
4384
by: Jatinder | last post by:
I 'm a professional looking for the job.In interview these questions were asked with some others which I answered.But some of them left unanswered.Plz help. Here are some questions on C/C++, OS internals? Q1 . What is the use of pointer to an array? Q2 . What is the use of array of pointers? Q3 . What is the use of pointer to function ? Q4 . How to print through serial port? What is Flow Control(Xon,Xoff) ?
24
1722
by: Kevin | last post by:
Hey guys. I'm looking to get together some VB programmers on Yahoo messenger. I sit at a computer and program all day. I have about 3 or 4 people already, but it would be really cool to have a much larger list of people (for all of us to benefit). I have found it to be an invaluable resource to answer those hard or weird programming questions that come up. If you are interested, please reply, or send me an email at imgroup@gmail.com
7
2361
by: changs | last post by:
Hi, all I have a asm code, I suspect it sort of socket programming. Can anyone here give some instructions on how to determine the function or give the psudo-code in C? Thanks in advance! Tony
3
1641
by: iKiLL | last post by:
Hi all I am building an Windows Mobile 5 forms control in C#, for a Windows Mobile 5 application. I am using CF2.0 and SQL Mobile 2005. The control is a Questions and answer control.
4
1591
by: Mr. X. | last post by:
Hello. I need some help, please. What can an employee ask (technical questions), if I am interviewed of Dot-net developer (also VB.NET and C#). (What are the most general questions, that I may be asked ?) Is there a site that has some questions & answers ? Thanks :)
30
2300
by: GeorgeRXZ | last post by:
Hi Friends, I have some questions related to C Language. 1What is the difference between the standard C language and Non standard C language ? 2which is better C Lanugage, C under Linux/ Unix or C under windows/ DOS ?
0
9588
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
10589
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
10340
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...
0
10085
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...
0
9161
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5527
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
5663
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4302
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3828
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.