Monday, March 29, 2010

comp.lang.c - 25 new messages in 8 topics - digest

comp.lang.c
http://groups.google.com/group/comp.lang.c?hl=en

comp.lang.c@googlegroups.com

Today's topics:

* OT: Linux problem - 8 messages, 6 authors
http://groups.google.com/group/comp.lang.c/t/b27bbc7383c9d155?hl=en
* 16:32 far pointers in OpenWatcom C/C++ - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c/t/4728dadef590aafe?hl=en
* Structure - 3 messages, 2 authors
http://groups.google.com/group/comp.lang.c/t/b86eaae8924c46a3?hl=en
* Wanted - example program to execute stack - 6 messages, 6 authors
http://groups.google.com/group/comp.lang.c/t/15477a0ce4b244e3?hl=en
* Letter sent to Apress with concerns about Peter Seebach's online behavior -
1 messages, 1 author
http://groups.google.com/group/comp.lang.c/t/482b38643777da3c?hl=en
* Implementing strstr - 4 messages, 2 authors
http://groups.google.com/group/comp.lang.c/t/a3fe05ab352d5774?hl=en
* How to check data input - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c/t/47d80150d7d879a9?hl=en
* Strange run time error - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c/t/26de5e1e7c96cfe0?hl=en

==============================================================================
TOPIC: OT: Linux problem
http://groups.google.com/group/comp.lang.c/t/b27bbc7383c9d155?hl=en
==============================================================================

== 1 of 8 ==
Date: Mon, Mar 29 2010 4:08 am
From: jacob navia


Igmar Palsenberg a écrit :
> On 3/29/10 11:17 AM, jacob navia wrote:
>> I have a problem:
>> I need to figure out why a program is crashing under linux 64 bits.
>>
>> I need a utility like Dr Watson under windows that would allow me to see
>> a stak trace and a register dump. Is there a&nything like that under
>> linux?
>
> Use GDB
>
>
> Igmar

No I can't. There is no debugger. I just want something that will write a
stack trace and register dump to a log file at the customer site...

I know gdb but this is not possible.

Thanks anyway

jacob


== 2 of 8 ==
Date: Mon, Mar 29 2010 4:42 am
From: Ben Bacarisse


jacob navia <jacob@nospam.org> writes:

> Igmar Palsenberg a écrit :
>> On 3/29/10 11:17 AM, jacob navia wrote:
<snip>
>>> I need a utility like Dr Watson under windows that would allow me to see
>>> a stak trace and a register dump. Is there a&nything like that
>>> under linux?
>>
>> Use GDB
>
> No I can't. There is no debugger. I just want something that will write a
> stack trace and register dump to a log file at the customer site...

You really need to ask in a Unix/Linux group. You must have a
peculiar situation if there is no gdb and that will need specialist
advice. Remember to give as much detail as you can.

--
Ben.


== 3 of 8 ==
Date: Mon, Mar 29 2010 5:07 am
From: Rob Kendrick


On Mon, 29 Mar 2010 13:08:23 +0200
jacob navia <jacob@nospam.org> wrote:

> No I can't. There is no debugger. I just want something that will
> write a stack trace and register dump to a log file at the customer
> site...

If it's a matter of not wanting to explain to the customer how to drive
GDB over the 'phone, then perhaps valgrind would be a better option?
(As it essentially requires no human to drive, and just dumps out a
report.)

B.


== 4 of 8 ==
Date: Mon, Mar 29 2010 5:45 am
From: jacob navia


Rob Kendrick a écrit :
> On Mon, 29 Mar 2010 13:08:23 +0200
> jacob navia <jacob@nospam.org> wrote:
>
>> No I can't. There is no debugger. I just want something that will
>> write a stack trace and register dump to a log file at the customer
>> site...
>
> If it's a matter of not wanting to explain to the customer how to drive
> GDB over the 'phone,

Customer (C): Your DAMMED programmed crashed AGAIN you MORON!
Jacob(j): Gulp... Sorry Sir, I can't explain it, I tested and tested.
Please can you open a command line?
C: A what?
j: A command line. You go into Applications, then Utilities and then
command line.
C: I can't see any "applications" I just see: "login".
j: Ah of course. Then you just write: root/password.
C: Now I see a black screen with a pound sign.
j: OK. Now you type:
cd /home/database/applications/start
C: It says -bash: /home is a directory
j: What? Ah OK. Do not put a space between the /home and the
directory word.

etc... etc... etc

Imagine explaining gdb to them. Besides, there is no core
file and gdb would be completely useless after the program
has exited.

> then perhaps valgrind would be a better option?
> (As it essentially requires no human to drive, and just dumps out a
> report.)

But it would affect performance isn't it?

I mean, my application doesn't crash all the time.

Thanks for your help.

jacob


== 5 of 8 ==
Date: Mon, Mar 29 2010 5:51 am
From: Tom St Denis


On Mar 29, 7:08 am, jacob navia <ja...@nospam.org> wrote:
> Igmar Palsenberg a écrit :
>
> > On 3/29/10 11:17 AM, jacob navia wrote:
> >> I have a problem:
> >> I need to figure out why a program is crashing under linux 64 bits.
>
> >> I need a utility like Dr Watson under windows that would allow me to see
> >> a stak trace and a register dump. Is there a&nything like that under
> >> linux?
>
> > Use GDB
>
> >     Igmar
>
> No I can't. There is no debugger. I just want something that will write a
> stack trace and register dump to a log file at the customer site...
>
> I know gdb but this is not possible.

If you're linking against glibc you can get a backtrace with the
backtrace() functionm, just call it from a signal handler for SIGSEGV.

Tom


== 6 of 8 ==
Date: Mon, Mar 29 2010 6:53 am
From: Ben Bacarisse


jacob navia <jacob@nospam.org> writes:

> Rob Kendrick a écrit :
>> On Mon, 29 Mar 2010 13:08:23 +0200
>> jacob navia <jacob@nospam.org> wrote:
>>
>>> No I can't. There is no debugger. I just want something that will
>>> write a stack trace and register dump to a log file at the customer
>>> site...
>>
>> If it's a matter of not wanting to explain to the customer how to drive
>> GDB over the 'phone,
>
> Customer (C): Your DAMMED programmed crashed AGAIN you MORON!
> Jacob(j): Gulp... Sorry Sir, I can't explain it, I tested and tested.
> Please can you open a command line?
> C: A what?
> j: A command line. You go into Applications, then Utilities and then
> command line.
> C: I can't see any "applications" I just see: "login".
> j: Ah of course. Then you just write: root/password.
> C: Now I see a black screen with a pound sign.
> j: OK. Now you type:
> cd /home/database/applications/start
> C: It says -bash: /home is a directory
> j: What? Ah OK. Do not put a space between the /home and the
> directory word.

Obviously that's not how one should do support. Why not ask in a
group where people will be able to discuss all the options that are
available to you? Remember to tell people there what constraints you
are working under along with as much as possible about the target
environment.

<snip>
--
Ben.


== 7 of 8 ==
Date: Mon, Mar 29 2010 9:36 am
From: Branimir Maksimovic


On Mon, 29 Mar 2010 14:45:49 +0200
jacob navia <jacob@nospam.org> wrote:

>
> Imagine explaining gdb to them. Besides, there is no core
> file and gdb would be completely useless after the program
> has exited.

Well you can enable core file , with setrlimit (RLIMIT_CORE).
If you can examine logs on user machine, then you can download
core file and examine in your machine with gdb, too.
Core file is far better anyway than plain log,
as you can debug program and examine situation.
Of course don't forget to compile with debug info (-g option)
so you can trace with source code, not just function names.

Greets!


--
http://maxa.homedns.org/

Sometimes online sometimes not


== 8 of 8 ==
Date: Mon, Mar 29 2010 9:43 am
From: Mark Bluemel


On Mar 29, 10:17 am, jacob navia <ja...@nospam.org> wrote:
> I have a problem:
> I need to figure out why a program is crashing under linux 64 bits.
>
> I need a utility like Dr Watson under windows that would allow me to see
> a stak trace and a register dump. Is there a&nything like that under linux?
>
> Thanks

Why not ask in a newsgroup where you don't believe it to be OT, such
as comp.unix.programmer?

You might want to tell them a) what you mean by "crashing" and b) why
you don't get a core file that can be examined.

(see http://www.catb.org/~esr/faqs/smart-questions.html)

==============================================================================
TOPIC: 16:32 far pointers in OpenWatcom C/C++
http://groups.google.com/group/comp.lang.c/t/4728dadef590aafe?hl=en
==============================================================================

== 1 of 1 ==
Date: Mon, Mar 29 2010 4:37 am
From: jmfbahciv


Mark Crispin wrote:
> On Sat, 27 Mar 2010, Peter Flass posted:
>> As has been said here many times, different languages have different
>> problem domains. Most of the trouble people have is caused by using
>> the wrong language for what they're trying to do. It used to be
>> Fortran or COBOL, now, apparently, it's stuff like Java.
>
> The attraction of Java is obvious; you can hire cheap inexperienced
> unskilled individuals to crank out Java code.
>
> Typically, a fair amount of a programming class washes out when you get
> to teaching pointers and structures. Some wash out even earlier on
> recursion. These individuals were lost to employers, who had to spend a
> great deal more on skilled individuals who could understand such things.
>
> Java fixed that. Thanks to Java, any snot-nosed kid can write Important
> Applications.

Too bad they aren't COBOL coders. That's more "sane".
>
> They just won't be very robust applications. Which is why I have to
> reboot my BlackBerry on a more or less daily basis after it pukes about
> some unhandled Java exception.
>
That's horrible.

==============================================================================
TOPIC: Structure
http://groups.google.com/group/comp.lang.c/t/b86eaae8924c46a3?hl=en
==============================================================================

== 1 of 3 ==
Date: Mon, Mar 29 2010 4:24 am
From: Ali Karaali


A structure is a special case that you can aggregate types in a single
special type.
For instance;
You need a Student type. Student type consists of a name and a student
ID which
are a string and an integer respectively.
You can aggregate these two types in a single Student type.

int main()
{
struct Student {
char name[20];
int ID;
};

//and you can access these element by using dot . operator.

struct Student student = {Ali, 112};
printf("%s", student.name);
printf("%d", student.ID);
}

Ali

On 29 Mart, 12:09, sanjidur095423 <sanjii...@gmail.com> wrote:
> HI,
> My name is Sanjidur,a student of IUT.I've a question that "What is the
> structure?".
>
> Any reply will be gratefully appreciated.
> Sanjidur095423.

== 2 of 3 ==
Date: Mon, Mar 29 2010 4:26 am
From: Ali Karaali


On 29 Mart, 14:24, Ali Karaali <ali...@gmail.com> wrote:
> A structure is a special case that you can aggregate types in a single
> special type.
> For instance;
> You need a Student type. Student type consists of a name and a student
> ID which
> are a string and an integer respectively.
> You can aggregate these two types in a single Student type.
>
> int main()
> {
>  struct Student {
>     char name[20];
>     int ID;
>  };
>
> //and you can access these element by using dot . operator.
>
>  struct Student student = {Ali, 112};

it should be "Ali" obviously.

>  printf("%s", student.name);
>  printf("%d", student.ID);
>
> }
>
> Ali
>
> On 29 Mart, 12:09, sanjidur095423 <sanjii...@gmail.com> wrote:
>
> > HI,
> > My name is Sanjidur,a student of IUT.I've a question that "What is the
> > structure?".
>
> > Any reply will be gratefully appreciated.
> > Sanjidur095423.
>
>

== 3 of 3 ==
Date: Mon, Mar 29 2010 4:46 am
From: "paul"


> My name is Sanjidur,a student of IUT.I've a question that "What is the
> structure?".
>

http://en.wikipedia.org/wiki/Struct_(C_programming_language)


==============================================================================
TOPIC: Wanted - example program to execute stack
http://groups.google.com/group/comp.lang.c/t/15477a0ce4b244e3?hl=en
==============================================================================

== 1 of 6 ==
Date: Mon, Mar 29 2010 5:33 am
From: "Dr. David Kirkby"


On Mar 29, 10:22 am, jacob navia <ja...@nospam.org> wrote:
> Dr. David Kirkby a écrit :
>
> > Can anyone give me a noddy example of a C program that tries to
> > execute the stack? I want to create a test to see if an operating
> > system is configured with stack protection or not.
>
> > Apparently on SELinux one can use 'setstatus' to determine if stack
> > protection is in operation or not, but I'd like a test which avoided
> > having to find a test for each platform, if a program could be made to
> > test it.
>
> > The The Number Theory Library (NTL) is one application which tries to
> > execute the stack and causes problems if stack protection is in use. I
> > suspect this is a bug in NTL, though it might be done for speed
> > reasons - lots of highly optimised maths code does unusual things.
>
> > Dave
>
> For x86 architectures:
>
> typedef void(*voidfn)(void);
> int main(void)
> {
>         char a[2] = {0xc3,0};
>         voidfn fnptr = (voidfn)a;
>         fnptr();
>
> }
>
> If that works and doesn't crash there is NO stack execution protection.

Thank you very much. I tested this on my OpenSolaris 06/2009 (quad
core Intel Xeon) workstation and it behaves as you say. First the
program did not crash, then when I set:

set noexec_user_stack=1
set noexec_user_stack_log=1

in /etc/system (which enables stack protection), so it crashed.

I must admit, I don't fully understand why it works, so any help on
that matter would be appreciated.

I also tried it on a linux box (I do not know what release it is, but
it crashed on their too. What is odd, is that Sage maths program
builds on that machine, despite failing to do so on other linux
systems unless stack protection is enabled.

I also need to know what is the significance of 0xc3,0. I thought it
might be a 'noop' but that does not appear to be the case. Perhaps it
is just some random (but valid) x86 instruction. I need to find one
for SPARC too and ideally Intel Itanium too, though the later is far
less important.

I'm somewhat puzzled why this should crash on a Linux (x86) server,
which executes code that another linux system complains about
execution of the stack.

Dave


== 2 of 6 ==
Date: Mon, Mar 29 2010 7:00 am
From: Ben Bacarisse


"Dr. David Kirkby" <david.kirkby@onetel.net> writes:

> On Mar 29, 10:22 am, jacob navia <ja...@nospam.org> wrote:
>> Dr. David Kirkby a écrit :
>>
>> > Can anyone give me a noddy example of a C program that tries to
>> > execute the stack? I want to create a test to see if an operating
>> > system is configured with stack protection or not.
>>
>> > Apparently on SELinux one can use 'setstatus' to determine if stack
>> > protection is in operation or not, but I'd like a test which avoided
>> > having to find a test for each platform, if a program could be made to
>> > test it.
>>
>> > The The Number Theory Library (NTL) is one application which tries to
>> > execute the stack and causes problems if stack protection is in use. I
>> > suspect this is a bug in NTL, though it might be done for speed
>> > reasons - lots of highly optimised maths code does unusual things.
>>
>> > Dave
>>
>> For x86 architectures:
>>
>> typedef void(*voidfn)(void);
>> int main(void)
>> {
>>         char a[2] = {0xc3,0};
>>         voidfn fnptr = (voidfn)a;
>>         fnptr();
>>
>> }
>>
>> If that works and doesn't crash there is NO stack execution protection.
<snip>
> I also need to know what is the significance of 0xc3,0. I thought it
> might be a 'noop' but that does not appear to be the case. Perhaps it
> is just some random (but valid) x86 instruction.

It's "return from procedure" which is, under the circumstances,
exactly what you want.

<snip>
> I'm somewhat puzzled why this should crash on a Linux (x86) server,
> which executes code that another linux system complains about
> execution of the stack.

You are likely to get a better answer on a Unix or Linux group.
comp.unix.programmer is a reasonable guess since you have questions
about more than one Unix variant.

--
Ben.


== 3 of 6 ==
Date: Mon, Mar 29 2010 8:03 am
From: "bartc"


Dr. David Kirkby wrote:
> On Mar 29, 10:22 am, jacob navia <ja...@nospam.org> wrote:
>> Dr. David Kirkby a écrit :
>>
>>> Can anyone give me a noddy example of a C program that tries to
>>> execute the stack? I want to create a test to see if an operating
>>> system is configured with stack protection or not.

>> typedef void(*voidfn)(void);
>> int main(void)
>> {
>> char a[2] = {0xc3,0};
>> voidfn fnptr = (voidfn)a;
>> fnptr();
>>
>> }
>>
>> If that works and doesn't crash there is NO stack execution
>> protection.
>
> Thank you very much. I tested this on my OpenSolaris 06/2009 (quad
> core Intel Xeon) workstation and it behaves as you say. First the
> program did not crash, then when I set:
>
> set noexec_user_stack=1
> set noexec_user_stack_log=1
>
> in /etc/system (which enables stack protection), so it crashed.

> I also need to know what is the significance of 0xc3,0. I thought it

0xC3 is a ret instruction. In other words, an empty function containing only
return. But this only works on x86 machines.

Not sure about the 0 though.

--
Bartc

== 4 of 6 ==
Date: Mon, Mar 29 2010 7:04 am
From: "paul"


>> typedef void(*voidfn)(void);
>> int main(void)
>> {
>> char a[2] = {0xc3,0};
>> voidfn fnptr = (voidfn)a;
>> fnptr();
>>
>> }

> I must admit, I don't fully understand why it works, so any help on
> that matter would be appreciated.

The bytes 0xc3 and 0x0 are placed onto the stack.
'a' is a points to these bytes.

fnptr is a pointer to a function. It is made to point to the same
address as 'a' (i.e. those bytes on the stack) using a cast.

They are then executed by calling what is pointed to by fnptr.
If stack protection is off, they will execute fine.

0xc3 is the 'ret' instruction. If it is able to execute then it returns
back to where it was called from (i.e. main) without problems
(by popping the return address into the instruction pointer.)


== 5 of 6 ==
Date: Mon, Mar 29 2010 7:11 am
From: Noob


Dr. David Kirkby wrote:

> I must admit, I don't fully understand why it works, so any help on
> that matter would be appreciated.

comp.lang.c is not the right newsgroup for your question.

comp.lang.asm.x86 may answer your x86 and NX questions.

( http://en.wikipedia.org/wiki/NX_bit )

> I also tried it on a linux box (I do not know what release it is, but
> it crashed on there too. What is odd, is that Sage maths program
> builds on that machine, despite failing to do so on other linux
> systems unless stack protection is enabled.
>
> I also need to know what is the significance of 0xc3,0. I thought it
> might be a 'noop' but that does not appear to be the case. Perhaps it
> is just some random (but valid) x86 instruction.

C3 is the IA-32 return instruction.
http://www.sandpile.org/ia32/

> I need to find one
> for SPARC too and ideally Intel Itanium too, though the later is far
> less important.
>
> I'm somewhat puzzled why this should crash on a Linux (x86) server,
> which executes code that another linux system complains about
> execution of the stack.

comp.os.linux.development.apps and comp.os.linux.development.system
may answer your Linux-specific questions.

Regards.


== 6 of 6 ==
Date: Mon, Mar 29 2010 9:13 am
From: jacob navia


Dr. David Kirkby a �crit :
> On Mar 29, 10:22 am, jacob navia <ja...@nospam.org> wrote:
>> Dr. David Kirkby a �crit :
>>
>>> Can anyone give me a noddy example of a C program that tries to
>>> execute the stack? I want to create a test to see if an operating
>>> system is configured with stack protection or not.
>>> Apparently on SELinux one can use 'setstatus' to determine if stack
>>> protection is in operation or not, but I'd like a test which avoided
>>> having to find a test for each platform, if a program could be made to
>>> test it.
>>> The The Number Theory Library (NTL) is one application which tries to
>>> execute the stack and causes problems if stack protection is in use. I
>>> suspect this is a bug in NTL, though it might be done for speed
>>> reasons - lots of highly optimised maths code does unusual things.
>>> Dave
>> For x86 architectures:
>>
>> typedef void(*voidfn)(void);
>> int main(void)
>> {
>> char a[2] = {0xc3,0};
>> voidfn fnptr = (voidfn)a;
>> fnptr();
>>
>> }
>>
>> If that works and doesn't crash there is NO stack execution protection.
>
> Thank you very much. I tested this on my OpenSolaris 06/2009 (quad
> core Intel Xeon) workstation and it behaves as you say. First the
> program did not crash, then when I set:
>
> set noexec_user_stack=1
> set noexec_user_stack_log=1
>
> in /etc/system (which enables stack protection), so it crashed.
>
> I must admit, I don't fully understand why it works, so any help on
> that matter would be appreciated.
>

I build a one instruction function that executes a "return"
Since the instruction is in the stack, if you can execute instructions
in the stack it doesn't crash, but if stack execution prevention is on
it will crash.

The return instruction just tells the processor to return to the calling procedure
(main)

jacob

==============================================================================
TOPIC: Letter sent to Apress with concerns about Peter Seebach's online
behavior
http://groups.google.com/group/comp.lang.c/t/482b38643777da3c?hl=en
==============================================================================

== 1 of 1 ==
Date: Mon, Mar 29 2010 6:17 am
From: Lubow


On Mar 29, 6:14 am, Dr Malcolm McLean <malcolm.mcle...@btinternet.com>
wrote:
> On 29 Mar, 09:11, blm...@myrealbox.com <blm...@myrealbox.com> wrote:> In article <4260ec09-7c2b-446a-a98d-db5631010...@t23g2000yqt.googlegroups.com>,
> > Dr Malcolm McLean  <malcolm.mcle...@btinternet.com> wrote:
>
> > > Though it's surprising how seldom people will admit that a book they
> > > disagree with is well-written.
>
> > Generally speaking, yes, probably so, but don't we have a perennial
> > counter-example in discussions in this group (comments to the effect
> > that Schildt's books are well-written but deeply flawed with regard
> > to content)?
>
> Well spotted.
> Maybe technical people are more open-minded than those with an arts or
> philosophical training.

Kindly avoid X-posting to misc.invest.stocks. Thank you.

==============================================================================
TOPIC: Implementing strstr
http://groups.google.com/group/comp.lang.c/t/a3fe05ab352d5774?hl=en
==============================================================================

== 1 of 4 ==
Date: Mon, Mar 29 2010 6:22 am
From: Ben Bacarisse


blmblm@myrealbox.com <blmblm@myrealbox.com> writes:

> In article <7d8e051d-6d2d-4b17-acdc-a7c0d218d1b6@t34g2000prm.googlegroups.com>,
> spinoza1111 <spinoza1111@yahoo.com> wrote:
<snip>
>> > spinoza1111 <spinoza1...@yahoo.com> wrote:
<snip>
>> > > The following code, from Peter's "pseudo root simulator", is submitted
>> > > to this discussion group [...]
<snip>
>> > > int
>> > > pseudo_server_response(pseudo_msg_t *msg, const char *tag) {
>> > > switch (msg->type) {
>> > > case PSEUDO_MSG_PING:
>> > > msg->result = RESULT_SUCCEED;
>> > > if (opt_l)
>> > > pdb_log_msg(SEVERITY_INFO, msg, tag, "ping");
>> > > return 0;
>> > > break;
>> > > case PSEUDO_MSG_OP:
>> > > return pseudo_op(msg, tag);
>> > > break;
>> > > case PSEUDO_MSG_ACK:
>> > > case PSEUDO_MSG_NAK:
>> > > default:
>> > > pdb_log_msg(SEVERITY_WARN, msg, tag, "invalid message");
>> > > return 1;
>> > > }
>> > > }
<snip>
>> It was both, because Seebach (because he didn't study computer
>> science) has no committment to the Copernican revolution of structured
>> programming, and he thinks it's cute to fall through like Alice in the
>> Rabbit hole. Most competent instructors would lower his grade for
>> using this "feature".
>
> I would not. Whether this makes me an exception to the rule or marks
> me as not competent -- <shrug>.

No, neither would I, and there is an significant technical issue here.

The code above does not "fall through" in the way the term is usually
used -- it just labels some code with more than one case label.
This is simply what you do when more than once case should be handled
in the same way and there is nothing unstructured about it. Some
languages permit the multiple cases to be abbreviated, but that does
not alter the structure.

What is (at first glance) a little odd is that two explicit cases have
been added to a default cause. One has to ask if the added
documentary value in making these explicit is worthwhile. I'd say
that it is -- particularly if all switch statements that switch on the
message type explicitly include these four cases.

<snip>
--
Ben.


== 2 of 4 ==
Date: Mon, Mar 29 2010 10:15 am
From: Seebs


On 2010-03-29, blmblm myrealbox.com <blmblm@myrealbox.com> wrote:
> Then you're missing lots and lots of nasty slurs .... I gather
> that this doesn't bother you, though,

Honestly, it does. I really feel like I'm missing some prime humor here,
but it's really hard to read his hilarious nonsense without feeling compelled
to try to correct some reasonable subset of the technical errors, whereupon
everyone yells at me for wasting bandwidth.

> I'm trying to
> only quote when I think there's a technical point that might be of
> interest to other readers.

Well, his "technical criticisms" of pseudo have indeed been fascinating to
me. I admit that his technical ability surprised me; I thought I'd
established a reasonable working lower bound for him, but I was wrong again.

-s
--
Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam@seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!


== 3 of 4 ==
Date: Mon, Mar 29 2010 10:12 am
From: Seebs


On 2010-03-29, Old Wolf <oldwolf@inspire.net.nz> wrote:
> On Mar 19, 11:34�pm, spinoza1111 <spinoza1...@yahoo.com> wrote:
>> // * Arduously and ignobly like unto the meanest Hind � � � � � �*
>> // * That knoweth not his Elbow from his Behind. � � � � � � � � *
>> � � printf("Expect '0': %c\n", *strstr("0123456789", "0"));
> [etc.]

> This is quite possibly the worst C code
> I have ever had the misfortune of seeing.

And unless that's intended as a test of the library's code, there's not
even any guarantee that it's doing what it's supposed to do, because
strstr() is in implementation namespace.

But yeah, his code seems to be like that. Thus far, his big complaint about
my code has been that he doesn't know how switch() works and he can't tell
a pointer from a plain object.

-s
--
Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam@seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!


== 4 of 4 ==
Date: Mon, Mar 29 2010 10:25 am
From: Seebs


On 2010-03-29, blmblm myrealbox.com <blmblm@myrealbox.com> wrote:
> In article <1d64f717-1eb1-4c41-a98f-ac1d060cd2e6@v34g2000prd.googlegroups.com>,
> spinoza1111 <spinoza1111@yahoo.com> wrote:
>> Well hoo fucking ray: but it's bad style to /* FALLTHROUGH */, Alice
>> in Wonderland. It happens to be a basic violation of structured
>> programming rules, and it's rarely necessary. The resulting switch
>> cannot with fallthrough be recoded as if then else, and switch isn't
>> one of the Bohm Jacopini primitives.

> Depends where the fallthrough occurs, no?

Furthermore, why on earth would I care?

I do actually have at least one case where a fallthrough is used to
allow two cases in a switch to share code with several other cases.
(Note that this can be handled by a nested if.)

switch (x) {
case 0:
printf("roly poly ");
/* FALLTHROUGH */
case 1: case 2:
printf("fish heads\n");
break;
default:
printf("sorry, can't think of any other songs.\n");
break;
}

===

if (x == 0 || x == 1 || x == 2) {
if (x == 0) {
printf("roly poly ");
}
printf("fish heads\n");
} else {
printf("sorry, can't think of any other songs.\n");
}

But who CARES? I'm not here to comply with an arbitrary set of abstract
"rules of structured programming". I'm here to write clear, legible, C,
conforming to the conventions and idioms of that language.

> (Aside to Seebs: I was going to include /* FALLTHROUGH */ comments
> but realized I wasn't sure where they should go. ? )

There isn't a completely general convention. Usually, they go precisely
where the "break;" would have gone if there were no fallthrough, except
that sometimes they're put on the case labels rather than at the end of
the material under the case.

>> > The reason for this is that ACK and NAK are responses that are by
>> > DEFINITION sent only by the server. The client MUST NOT generate either
>> > such message. Therefore, they are an "invalid message", as is any
>> > other message of an unknown type.

>> Then you should have indicated this, Alice, in the structure of the
>> code, by calling an error routine or using a macro, since there was no
>> reason to be unstructured. Your style is unprofessional and
>> amateurish.

This criticism is particularly illucid, simply because the original complaint
given was that I should not have called an error routine for those cases.

But in fact, I did exactly that -- I wrote code to call an error routine
if those ever occur.

>> > But I will go add the /* FALLTHROUGH */ comments to make it more
>> > explicit. I'd say "good catch" if it weren't so stunningly obvious
>> > that Nilges hadn't read, say, the documentation provided with the
>> > project which clearly indicates what ACK and NAK mean and when
>> > they are valid.

>> I'd rather not read your "documentation". As it is, I decided to focus
>> on queue.c in the same superficial style in which you went through
>> Schildt. How does it feel, asshole?

It feels like you're dumber than I could possibly imagine. The key
distinction, I think, being that my criticisms of Schildt are actually
correct, whereas your criticisms of my code so far show an astounding
lack of comprehension of basic C.

>> Each separate module, after TWO MONTHS work, should be readable
>> standalone.

Up to a point, yes. There is a reason to have high-level documentation,
though, which is that no amount of "readable" makes up for the reader
not understanding the basic goal of the program.

>> Not by random silly comments by architectonally.

Colorless green ideas sleep furiously!

>> If ACK
>> and NAK were invalid from the client, and that is client code, then
>> don't put cases in for them.

But that's not client code.

Come on, really. What function had the disputed MSG_ACK and MSG_NAK?

"pseudo_server_response()"

I do not think it is reasonable for anyone to suspect that this is
"client code".

As to whether I should put in cases for an "invalid" condition: One of the
reasons pseudo exists is that other tools we'd used were not robust enough;
they could crash or otherwise fail. As such, pseudo is full of tests for
conditions that are obviously impossible *if the rest of the code is free
of bugs*. What this means is that even when there have been bugs (and there
have), the program has continued to work, with a grand total of one reported
failure in the field.

At one point during internal testing, I had a bug in the server which caused
it to crash under fairly common circumstances. It went unnoticed for a
week or two because the recovery code kept things running smoothly anyway.

-s
--
Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam@seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!

==============================================================================
TOPIC: How to check data input
http://groups.google.com/group/comp.lang.c/t/47d80150d7d879a9?hl=en
==============================================================================

== 1 of 1 ==
Date: Mon, Mar 29 2010 8:29 am
From: Keith Thompson


Dr Malcolm McLean <malcolm.mclean5@btinternet.com> writes:
> On 29 Mar, 08:32, Mok-Kong Shen <mok-kong.s...@t-online.de> wrote:
>> If I with scanf input a couple of hex values to unsigned long int with
>> %x and there is error in data, e.g. 3g, how could I check that so that
>> I could repeat the scanf statement?
>>
> if( scanf("%lx %lx", &a, &b) == 2)
> /* scanf successfully converted two long int values */
> else
> /* scanf was unsuccessful. You need some sort of flow control to go
> back
> to your scanf() call and try again */
>
> However Richard's advice to avoid scanf() is good. It's hard to write
> a bulletproof interface with scanf() that will react correctly to all
> user errors.

In fact, I believe it's impossible, at least if you use the numeric
input formats such as "%lx". If the value being read is outside the
range of the target type, the behavior is undefined.

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

==============================================================================
TOPIC: Strange run time error
http://groups.google.com/group/comp.lang.c/t/26de5e1e7c96cfe0?hl=en
==============================================================================

== 1 of 1 ==
Date: Mon, Mar 29 2010 10:30 am
From: sandeep


Hello

I am reminding myself of C after many years. I have found a very strange
run time error, "Segmentation Fault", I don't remember ever seeing this.
There are no compiler errors! What is wrong with my code??

main(char * argv [], int argc)
{
char NAME[1024 * sizeof (char)] = {0}; // declare static array
// build up the output buffer
if ( strlen (argv[1]) > 1000 ) {
printf("Buffer overflow error please restart");
abort();
}
strcpy(NAME, "Hello ");
strcat(NAME, argv[1]);
strcat(NAME, " have a nice day");
// display the buffer
printf(NAME);
}


==============================================================================

You received this message because you are subscribed to the Google Groups "comp.lang.c"
group.

To post to this group, visit http://groups.google.com/group/comp.lang.c?hl=en

To unsubscribe from this group, send email to comp.lang.c+unsubscribe@googlegroups.com

To change the way you get mail from this group, visit:
http://groups.google.com/group/comp.lang.c/subscribe?hl=en

To report abuse, send email explaining the problem to abuse@googlegroups.com

==============================================================================
Google Groups: http://groups.google.com/?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate