473,770 Members | 6,158 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

elementary construction +1

I'm now looking at page 115 K&R. After having discussed counterexamples , I
shall herewith and henceforth make all my c programs look like

int main(int orange, char* apple[])
{return(0);}

Q1) How large is that int and that char*? (My instinct would be to look at
limits.h, but with the main call, I can't figure out to what extent I'm
%inside% C.)

Q2) The example on 115 completely confuses me. That which is printf'ed
looks like a batch file. How would the output change if the e in echo were
omitted? MPJ
Nov 14 '05 #1
29 1881
Merrill & Michele <be********@com cast.net> scribbled the following:
I'm now looking at page 115 K&R. After having discussed counterexamples , I
shall herewith and henceforth make all my c programs look like int main(int orange, char* apple[])
{return(0);} Q1) How large is that int and that char*? (My instinct would be to look at
limits.h, but with the main call, I can't figure out to what extent I'm
%inside% C.)


It depends what you mean by "large". If you mean how many bytes they
take up, then the sizeof operator is your friend. Try sizeof orange or
sizeof apple.

Question Q2 snipped because I don't have K&R handy at the moment so I
don't know what example you're talking about.

--
/-- Joona Palaste (pa*****@cc.hel sinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Nothing lasts forever - so why not destroy it now?"
- Quake
Nov 14 '05 #2
Hi there,

I'm now looking at page 115 K&R. After having discussed counterexamples , I
shall herewith and henceforth make all my c programs look like

int main(int orange, char* apple[])
{return(0);}

Q1) How large is that int and that char*? (My instinct would be to look at
limits.h, but with the main call, I can't figure out to what extent I'm
%inside% C.)
Byte: sizeof orange, sizeof *apple
(if you meant apple itself, which equivalently could be declared
as a char **, sizeof apple)

Bit: the above times CHAR_BIT, from <limits.h>

Range: INT_MIN <= orange <= INT_MAX; for pointers, there is no general
pointer range but you are guaranteed a valid range within your
object (that is, apple[0] through apple[orange-1])

Q2) The example on 115 completely confuses me. That which is printf'ed
looks like a batch file. How would the output change if the e in echo were
omitted? MPJ


You are maybe not aware of it but there are translations of K&R to other
languages. For these, the page numbers are not the same. Apart from
that, some of the people who could help you maybe do not even possess
a copy of that book.
It might be better to just copy the example...
Cheers
Michael

Nov 14 '05 #3
> Range: INT_MIN <= orange <= INT_MAX; for pointers, there is no general
pointer range but you are guaranteed a valid range within your
object (that is, apple[0] through apple[orange-1])
That helps. I know that I can use sizeof for my implementation and
determine what holds for my machine. I'm trying to think of a way never to
get stung by a machine whose INT_MIN and INT_MAX I haven't accounted for.
The only thing I can think of right now is to pass argv [] to a
similar-sized matrix with fields the size of INT_MAX.
You are maybe not aware of it but there are translations of K&R to other
languages. For these, the page numbers are not the same. Apart from
that, some of the people who could help you maybe do not even possess
a copy of that book.
It might be better to just copy the example...


Dass unsre Bible nicht Eurer Bibel entspricht ist mir nicht eingefallen. Es
folgt K&R, zweite Ausgabe §5.10 dritter Absatz:

#include <stdio.h>
main(int argc, char *argv[])
{
int i;

for (i=1; i < argc; i++)
print f("%s%s", *++argv[i]; (i < argc-1) ? " " : "");
printf("\n");
return 0;
}

Wir waren neulich bei Euch. Eure Gastfreundschaf t ist legendaer. MPJ
Nov 14 '05 #4
Merrill & Michele wrote:
#include <stdio.h>
main(int argc, char *argv[])
{
int i;

for (i=1; i < argc; i++)
print f("%s%s", *++argv[i]; (i < argc-1) ? " " : "");
printf("%s%s", argv[i], i < argc - 1 ? " " : "");
printf("\n");
return 0;
}

#include <stdio.h>
main(int argc, char *argv[])
{
while (*++argv != NULL) {
printf("%s ", *argv);
}
putchar('\n');
return 0;
}

Under what conditions does the intial value of argc equal zero?

--
pete
Nov 14 '05 #5
Groovy hepcat Merrill & Michele was jivin' on Fri, 24 Sep 2004
12:41:20 -0500 in comp.lang.c.
elementary construction +1's a cool scene! Dig it!
I'm now looking at page 115 K&R. After having discussed counterexamples , I
shall herewith and henceforth make all my c programs look like

int main(int orange, char* apple[])
{return(0);}
Um..., OK.
Q1) How large is that int and that char*? (My instinct would be to look at
What char*? I don't see any char*. I see a char**. Sure it's
disguised as a char*[], but it's a char** alright. But I see no char*.
limits.h, but with the main call, I can't figure out to what extent I'm
%inside% C.)
What? That doesn't make sense. I have no idea what you're trying to
say.
Q2) The example on 115 completely confuses me. That which is printf'ed
Which one? There are two examples on page 115 (of my copy of K&R
anyhow).
looks like a batch file. How would the output change if the e in echo were
omitted? MPJ


What? What looks like a batch file? What sort of batch file? You
mean a DOS batch language file? In what way does it look like that?
What the hell have you been smoking? What e in what echo?
Oh, I think I see what you mean. On page 114 an example input is
given: "echo hello, world". Actually, the "echo" part is not the input
at all. It's the name of the program. Typing "echo hello, world" at a
command prompt would cause the program echo to output "hello, world".
The two code examples on page 115 are different versions of this echo
program.

--

Dig the even newer still, yet more improved, sig!

http://alphalink.com.au/~phaywood/
"Ain't I'm a dog?" - Ronny Self, Ain't I'm a Dog, written by G. Sherry & W. Walker.
I know it's not "technicall y correct" English; but since when was rock & roll "technicall y correct"?
Nov 14 '05 #6
Cheerio,

Range: INT_MIN <= orange <= INT_MAX; for pointers, there is no general
pointer range but you are guaranteed a valid range within your
object (that is, apple[0] through apple[orange-1])
That helps. I know that I can use sizeof for my implementation and
determine what holds for my machine. I'm trying to think of a way never to
get stung by a machine whose INT_MIN and INT_MAX I haven't accounted for.
The only thing I can think of right now is to pass argv [] to a
similar-sized matrix with fields the size of INT_MAX.


Umh, I do not have the least clue what you are talking about.
argc is either the number of arguments to the program call (including
the program name) or zero. In the first case, I can hardly think
of a program call taking 2^15-1 arguments, aside from the fact that
you probably do not get the command line into the buffer on some
systems. And you really do not want to have a typo or left-out
argument...

Maybe the process of getting from the command line to argc and argv
is not clear to you. I will give a very simple example of how they
_could_ be obtained:
- The shell gets a line and reads to the first white space.
It might use strtok() to put in a '\0' there. Then it looks in
the search path whether it can find an executable of that name.
- If it does, it runs through the rest of the command line obtaining
the number of non-white-space areas (that is, arguments).
- It allocates space for enough char * variables to point to the
start of each argument, that is: argv.
- It runs through the command line and points argv[i++] to the beginning
of the next parameter. Usually you combine that with strtok() to get
in the '\0' after the argument.
- Now, we have the command line still in the same place in memory
but interspersed with several '\0', thus making it into many strings.
argv[i] just contains a pointer to the (i+1)th argument.

You are maybe not aware of it but there are translations of K&R to other
languages. For these, the page numbers are not the same. Apart from
that, some of the people who could help you maybe do not even possess
a copy of that book.
It might be better to just copy the example...


Dass unsre Bible nicht Eurer Bibel entspricht ist mir nicht eingefallen. Es
folgt K&R, zweite Ausgabe §5.10 dritter Absatz:

#include <stdio.h>
main(int argc, char *argv[])
{
int i;

for (i=1; i < argc; i++)
printf("%s%s", *++argv[i]; (i < argc-1) ? " " : "");
printf("\n");
return 0;
}


Hmmm, okay. That does not tell me anything about the echo you have
been asking for. If I understand the posting of Peter Shaggy Haywood
correctly, echo seems to be the name of the program, usually pointed
to by argv[0] if argc>=1. Making this cho would not help as the
program could not be found (of course you could rename it to cho but
that is beside the point.

Is the rest of the program clear to you?

Wir waren neulich bei Euch. Eure Gastfreundschaf t ist legendaer.


Pleasant to hear; I was not aware that German hospitality is that
good...
HTH
Michael

Nov 14 '05 #7
Thanks all for your replies. While my question revealed glaring ignorance,
which was so amply discussed, the thrust of the question dealt with exactly
what argv[] was pointing to. Now that I'm three days wiser, it seems that
argv[0] points to a string with the path and program name in it. "Echo", by
the way, is a terrible name to call the program on K&R 115 because the
person working up his C game has to unlearn a lot of DOS. argv[argc]
points to null. My thinking that I needed to determine the sizes of these
pointers was fundamentally wrong-headed. Who cares how large they are when
you have argc+1 to tell you how many there are.

As for the root of misunderstandin g, I am going to cast aspersion on my
implementation. Finally, I'll run Pete's program soon here, as it is likely
quite helpful. Again, thanks all. MPJ
Nov 14 '05 #8
Merrill & Michele wrote:
Now that I'm three days wiser, it seems that
argv[0] points to a string with the path and program name in it.
It does if argc is positive. What if argc is zero?
Who cares how large they are when
you have argc+1 to tell you how many there are.
(argc + 0) is how many pointers to strings you have.
(argc - 1) is how many parameters you have.
Finally, I'll run Pete's program soon here, as it is likely
quite helpful.


I think that program is missing some code to guard against the
(argc == 0) case.

N869
5.1.2.2.1 Program startup
[#2] If they are declared, the parameters to the main
function shall obey the following constraints:
-- The value of argc shall be nonnegative.
-- argv[argc] shall be a null pointer.
-- If the value of argc is greater than zero, the array
members argv[0] through argv[argc-1] inclusive shall
contain pointers to strings, which are given
implementation-defined values by the host environment
prior to program startup. The intent is to supply to
the program information determined prior to program
startup from elsewhere in the hosted environment. If
the host environment is not capable of supplying
strings with letters in both uppercase and lowercase,
the implementation shall ensure that the strings are
received in lowercase.
-- If the value of argc is greater than zero, the string
pointed to by argv[0] represents the program name;
argv[0][0] shall be the null character if the program
name is not available from the host environment. If
the value of argc is greater than one, the strings
pointed to by argv[1] through argv[argc-1] represent
the program parameters.
-- The parameters argc and argv and the strings pointed to
by the argv array shall be modifiable by the program,
and retain their last-stored values between program
startup and program termination.

--
pete
Nov 14 '05 #9
In <41**********@m indspring.com> pete <pf*****@mindsp ring.com> writes:
Under what conditions does the intial value of argc equal zero?


The program was started with no parameters and its name is not available.
Or the implementation simply does not *meaningfully* support the argc/argv
mechanism:

- argv[argc] shall be a null pointer.

- If the value of argc is greater than zero, the array members
argv[0] through argv[argc-1] inclusive shall contain pointers
to strings,...

- If the value of argc is greater than zero, the string pointed
to by argv[0] represents the program name;...

An implementation where argc is *always* zero and argv[0] is a null
pointer trivially satisfies all these requirements.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Currently looking for a job in the European Union
Nov 14 '05 #10

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

Similar topics

1
1560
by: Anthony | last post by:
Hi, Can anyone help me out here, I'm looking for a design (pattern?) for a-synchronic construction of a class. I need this design in a framework which will run in a multithreaded system. I want a class (client) in threadA to a-synchronously construct a class (server) in threadB. Both threads will probably need a kind of construction manager object. For passing the request I will probably need to use a parameterised class.
2
1696
by: Steve | last post by:
Hi Folks, Sorry for this stupid question, but how do you handle errors during class construction. In other words, if I have a class that loads a file, and during loading, an error occurs, how do you deal with this in respect of releasing the resources that would have been allocated if the load was successful? What I am trying to achieve is, if I call my class with new, how do I return NULL if the construction fails (so I can check for...
14
1991
by: trying_to_learn | last post by:
i am on the chapter on copy construction in C++ in the code (see below), the author says if u pass the object by value as in HowMany h2 = f(h); ....then a bitwise object is created w/o calling the constructor of the class. However he says when we leave scope of function HowMany f(HowMany x) then the destructor is called. why this inconsistency?. Accdng to me even the destructor should *not* be called. i can understand that bit wise copy...
5
2847
by: Lionel B | last post by:
Greetings, I am trying to implement "element-wise" arithmetic operators for a class along the following lines (this is a simplified example): // ----- BEGIN CODE ----- struct X { int a,b;
0
2891
by: Geoffrey L. Collier | last post by:
I wrote a bunch of code to do elementary statistics in VB, and would prefer to find code in C# to recoding all of the VB code. A search of the web found very little. Does anyone know of a good set of classes to do these things, free, or for fee? Thanks, Geoff Collier
8
1510
by: pauldepstein | last post by:
I am writing a program which looks at nodes which have coordinates which are time-dependent. So I have a class called node which contains the private member declarations int date; int month; (I want to consider the month as part of the information contained in the node, as well as the date.) The node class also contains public member function void set_month(int) which sets the month according to the date given.
5
2535
by: bromio | last post by:
can someone help me to make code for digital clock using AT89S52. The specs of clock are 12 hour clock,am-pm display,use timer interrupts to have delay.two external inputs to adjust hours and minutes,use 4 digit hex display multiplexing.
7
3412
by: BeautifulMind | last post by:
In case of inheritence the order of execution of constructors is in the order of derivation and order of destructor execution is in reverse order of derivation. Is this case also true in case class is derived as virtual? How does the order of construction/destruction is impacted if the base class is derived as virtual or non virtual? just see the example below.
15
2408
by: Victor Bazarov | last post by:
Hello, Take a look at this program: ----------------------------------- class B { B(const B&); B& operator=(const B&); public: B(int);
0
9592
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9425
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
10059
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
9871
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
6679
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5313
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
5452
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3972
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
3
2817
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.