Re: Arrays is confusing

1999-04-08 Thread Vitaly Fedrushkov

Good $daytime,

 Date: Thu, 8 Apr 1999 16:39:22 +0530
 From: Anubhav Hanjura [EMAIL PROTECTED]
 To: UnixC [EMAIL PROTECTED]
 Subject: Arrays is confusing

Anubhav Why does this code give the strange output they give?

Pardon my ignorance, but what results did you regard as strange?  It
depends heavily on what you expected :)

In general, you can't safely rely on any particular order of
calculations -- with regard to side effects.

There are four operations:
  1) '++' within lvalue;
  2) '++' within rvalue;
  3) '[]', and
  4) '='.

Dependencies are:

++ after []   []
++ after =   /  \
=  after [] =   ++
|
++
Possible orders are:

 a) 3 1 4 2  [] ++ = ++ means   i[0] = 1
 b) 3 4 2 1  [] = ++ ++ means   i[0] = 0
 c) 3 4 1 2  [] = ++ ++ means   i[0] = 0

However, if optimizing compiler tries to postpone evaluation of 'j'
until next usage, result most likely will be b).

  Regards,
  Willy.

--
"No easy hope or lies| Vitaly "Willy the Pooh" Fedrushkov
 Shall bring us to our goal, | Information Technology Division
 But iron sacrifice  | Chelyabinsk State University
 Of Body, Will and Soul."| mailto:[EMAIL PROTECTED]  +7 3512 156770
   R.Kipling | http://www.csu.ac.ru/~willy  VVF1-RIPE



Re: your mail

1999-04-01 Thread Vitaly Fedrushkov

Good $daytime,

 To do some programming I use for instance EMACS. When I'm done I
 exit EMACS and run GCC and then run the program to see if it does
 the thing I want it to do. This procedure is time consuming and not
 eficient.

There is no need to exit any editor.  If you're running X windows, you
have both emacs and xterm at the same time.  If not, you may open
one console for editor and another for your shell.

But there's a better way!  Try `M-x compile' -- emacs will read gcc
output in another buffer.  Clicking mouse-2 over error message will
bring you to the line in question -- no need for extra IDE.

 Is there any compiler/editor/debugger-package anvailable from the
 internet? Or am I missing something here? I've noticed that MC has
 an edit feature which shows source code using different colours. I
 find this very helpfull.

There are many IDE-like products.  To see a few, look at freshmeat.net
appindex, section 'Development'.

Well, if you're looking forward to "attend the Church of Emacs" :),
try `M-x font-lock-mode'.  Emacs has nice syntax highlighting -- and
knows C/C++ to some extent.

Hope this helps...

  Regards,
  Willy.

--
"No easy hope or lies| Vitaly "Willy the Pooh" Fedrushkov
 Shall bring us to our goal, | Information Technology Division
 But iron sacrifice  | Chelyabinsk State University
 Of Body, Will and Soul."| mailto:[EMAIL PROTECTED]  +7 3512 156770
   R.Kipling | http://www.csu.ac.ru/~willy  VVF1-RIPE



Re: vim or emacs c syntax

1999-03-14 Thread Vitaly Fedrushkov

Good $daytime,

 Date: Sat, 13 Mar 1999 18:01:27 -0800
 From: Chris [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Subject: vim or emacs c syntax

 I was wondering how to make vim do syntax highlighting for C code or
 emacs and how to set tabs for code.

Well, here are these for emacs:

Try `M-x font-lock-mode' to turn on syntax highlighting.  With newer
emacsen, it is also at 'Help/Options/Global Font Lock' menu item.
To learn more, run `info emacs` and find section named 'Font Lock'.

Emacs has special C/C++ mode that 'knows' these languages enough to
calculate indentations according to some predefined coding style.  In
short, 'c-basic-offset' contains common tab size, used for most
things, and 'c-default-style' tells what style (gnu, kr, bsd, linux,
stroustrup).  You can try `C-c .' to change indentation style on a
file.  Open info page on 'ccmode' to learn more about these.

Hope this helps.

  Regards,
  Willy.

--
"No easy hope or lies| Vitaly "Willy the Pooh" Fedrushkov
 Shall bring us to our goal, | Information Technology Division
 But iron sacrifice  | Chelyabinsk State University
 Of Body, Will and Soul."| mailto:[EMAIL PROTECTED]  +7 3512 156770
   R.Kipling | http://www.csu.ac.ru/~willy  VVF1-RIPE



Re: ./configure

1999-02-22 Thread Vitaly Fedrushkov

Good $daytime,

 Date: Mon, 22 Feb 1999 22:47:00 + (GMT)
 From: James [EMAIL PROTECTED]
 To: Linux C Programming List [EMAIL PROTECTED]
 Subject: ./configure

 How do i make my own configure scripts? are they hand written or
 created by some special program?

The latter.  Look at 'info autoconf'.  Then try 'info automake', to
see how to write nice makefiles.

Hope this helps,

  Regards,
  Willy.

--
"No easy hope or lies| Vitaly "Willy the Pooh" Fedrushkov
 Shall bring us to our goal, | Information Technology Division
 But iron sacrifice  | Chelyabinsk State University
 Of Body, Will and Soul."| mailto:[EMAIL PROTECTED]  +7 3512 156770
   R.Kipling | http://www.csu.ac.ru/~willy  VVF1-RIPE



Re: summary: static variable in C++

1999-01-21 Thread Vitaly Fedrushkov

Good $daytime,

 Date: Wed, 20 Jan 1999 21:57:48 -0500
 From: Yasushi Shoji [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Subject: summary: static variable in C++

 case 1:
 if you declare static variable outsize of the class,
 that means the variable is global. so that, it is possible
 to access the static variable from outsize of a object.

   static int counter = 0;

   class base {
   public:
   base(void) {counter++;}
   ~base(void){counter--;}
   int get_counter(void) {return counter;}
   };

   int main(void) {
   base b;
   counter += 1; // this is ok;
   cout  b.get_counter();  // this prints 2
   }

This works indeed, but brings another small but fundamental problem:

 o  Namespace pollution: from now on, you can't have another object
named 'counter' without trouble.  This may be painful if your
software is a library.

 case2:
 you should initialize(or define?) static variable
 outside of the class declaration.

Should you define it?  Yes.  Should you initialise it?  Perhaps.
Consider an example.

   class base {
   private:
   static int counter;
   public:
   base(void) {counter++;}
   ~base(void){counter--;}
   int whatever(void);
   int get_counter(void) {return counter;}
   };

You may never implement base::whatever() -- as long as you don't use
it.  If you do, you should put somewhere:

   int base::whatever()
   {
...
   }

The same applies to base::counter.  You write

   int base::counter;

or

   int base::counter = 0;

'static int counter' and 'int whatever(void)' are _declarations_, used
primarily for type checking.

'int base::counter' and 'int base::whatever()' are _definitions_ that
actually create such object.

'= 0' is a way to statically _initialize_ a variable.  One can also
think of '{ ... }' being sort of "initial value" for a function body :)

 case3:
 because, in my example, static variable is private,
 you need a static function if you want to access to
 that static variable without an object.

Sure.

  Regards,
  Willy.

--
"No easy hope or lies| Vitaly "Willy the Pooh" Fedrushkov
 Shall bring us to our goal, | Information Technology Division
 But iron sacrifice  | Chelyabinsk State University
 Of Body, Will and Soul."| mailto:[EMAIL PROTECTED]  +7 3512 156770
   R.Kipling | http://www.csu.ac.ru/~willy  VVF1-RIPE



Re: static variable in C++

1999-01-20 Thread Vitaly Fedrushkov

Good $daytime,

 Date: Tue, 19 Jan 1999 15:36:16 -0500
 From: Yasushi Shoji [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Subject: static variable in C++

 trying to make a class with a static variable so that all objects
 instantiated for that class can share one variable.
 # hope i'm on the right road...

 Question 1:
   how can i initialize counter at (A) to 0?
   i replaced (A) with
   static int counter = 0;

Try this:

class base {
...
}

int base::counter = 0;

int
main()
{
...

   and compiler said:
   "ANSI C++ forbids in-class initialization 
of non-const static member `counter'"

 Question 2;
   it seems that linker is not able to link object files from
   the source code:

 bash$ g++ -Wall static.cpp
 /tmp/ccPYx1jJ.o: In function `base::get_counter(void)':
 /tmp/ccPYx1jJ.o(.base::gnu.linkonce.t.get_counter(void)+0x8): undefined reference to 
`base::counter'

The same answer.  You _declare_ a static variable but then forgot to
_define_ it.  Initial value is optional, but definition itself isn't.

C++-go o muzukashiku nai.

  Regards,
  Willy.

--
"No easy hope or lies| Vitaly "Willy the Pooh" Fedrushkov
 Shall bring us to our goal, | Information Technology Division
 But iron sacrifice  | Chelyabinsk State University
 Of Body, Will and Soul."| mailto:[EMAIL PROTECTED]  +7 3512 156770
   R.Kipling | http://www.csu.ac.ru/~willy  VVF1-RIPE



Re: novice: problem with serial I/O

1999-01-04 Thread Vitaly Fedrushkov

Good $daytime,

 Date: Sat, 2 Jan 1999 13:44:04 -0500 (GMT)
 From: Saraf Aalhad Ashok [EMAIL PROTECTED] 
 To: Vitaly Fedrushkov [EMAIL PROTECTED]
 Cc: [EMAIL PROTECTED], [EMAIL PROTECTED] 
 Subject: Re: novice: problem with serial I/O

 * I don't know how to do it any other way! Since I've programmed in
 assembly and C on DOS, and don't know much about termios.

Do you plan to stay :)

 * I'm developing a system for connecting together several 8051 based
 clients on an RS 485 physical layer. I've finished the rough draft
 of the specifications of the protocol that the system would
 use. However I am also considering an implemetation of the modbus
 protocol, since it is a widely accepted standard for SCADA systems.

Commodity PCs use RS-232, typically w/o synchronous options.  I can't
tell for sure, but RS-485 hardware may differ significantly from what
you are doing now.

None the less, I think of terminal I/O as the only right
(portable) approach to a problem.

 It would be great if I could get some pointers from you as to how I
 could go about doing this using termios.

Some time ago I learnt to drive termios myself.  Try `info libc` or
`info glibc` (depends on your distribution), and look at section
titled 'Low-Level Terminal Interface'.

 Also currently , my first goal is to write two simple programs, One
 program sending data to a serial port and that serial port being
 connected via a null modem cable to another serial port which is
 being monitored by another program which takes in incoming data and
 either shows it on the screen or appends it / writes it to a file.
 It's taking me a long time just to do this . Could you please tell
 me how to go about doing it?

Look at examples there, particularly within 'noncanonical mode'
discussion.

 I'd like to know whether and how termios facilities could be used
 for implementing the modbus protocol on a Linux machine.

Again, never worked with modbus.  However, I am interfacing with AVR
based controllers, and implemented SECS-1 protocol without any
trouble.

  Regards, 
  Willy.

--
"No easy hope or lies| Vitaly "Willy the Pooh" Fedrushkov
 Shall bring us to our goal, | Information Technology Division
 But iron sacrifice  | Chelyabinsk State University
 Of Body, Will and Soul."| mailto:[EMAIL PROTECTED]  +7 3512 156770
   R.Kipling | http://www.csu.ac.ru/~willy  VVF1-RIPE



Re: novice: problem with serial I/O

1999-01-02 Thread Vitaly Fedrushkov

Good $daytime,

 Date: Fri, 1 Jan 1999 10:31:27 -0500 (GMT)
 From: Saraf Aalhad Ashok [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Cc: [EMAIL PROTECTED]
 Subject: novice: problem with serial I/O

   I'm facing yet another problem. This time, it is about sending and
 receiving data from the serial ports. I've modified the program
 "example.c" given in the I/O programming mini-HOWTO to write two programs
 client.c and iserve.c. The iserve program running on the console sends out
 data to one serial port, and the client program running on a virtual
 terminal monitors the other serial port, the two serial ports being
 connected together by a serial cable. 
...

 #include stdio.h
 #include unistd.h
 #include asm/io.h

Are you sure you want to stay away from POSIX termios?  What if your
serial port will be Digiboard some day?

In other words, what is your reason in low level port access?

  Regards,
  Willy.

--
"No easy hope or lies| Vitaly "Willy the Pooh" Fedrushkov
 Shall bring us to our goal, | Information Technology Division
 But iron sacrifice  | Chelyabinsk State University
 Of Body, Will and Soul."| mailto:[EMAIL PROTECTED]  +7 3512 156770
   R.Kipling | http://www.csu.ac.ru/~willy  VVF1-RIPE



Re: vi-like + Color Syntax Highlighting?

1998-12-16 Thread Vitaly Fedrushkov

Good $daytime,

 Date: Tue, 15 Dec 1998 17:47:11 -0800
 From: Edward Roper [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Subject: vi-like + Color Syntax Highlighting?

 Anyone know of any editors that have color syntax highlighting yet
 have a vi-like interface? vi-like meaning edit + command mode. Being
 able to use h,j,k,l to move, .,$s///g substitutions, etc :) I've
 tried several C editors but keep finding myself hitting escape and
 inserting far too many hjkl's.

Have you tried emacs?  M-x viper-mode puts you into various levels of
vi emulation.  M-x font-lock-mode turns on syntax highlighting.  C/C++
mode also has some language background and may further reduce number
of hjkliaxd's needed for particular editing session.

  Regards,
  Willy.

--
"No easy hope or lies| Vitaly "Willy the Pooh" Fedrushkov
 Shall bring us to our goal, | Information Technology Division
 But iron sacrifice  | Chelyabinsk State University
 Of Body, Will and Soul."| mailto:[EMAIL PROTECTED]  +7 3512 156770
   R.Kipling | http://www.csu.ac.ru/~willy  VVF1-RIPE




Re: remove from the list?

1998-11-27 Thread Vitaly Fedrushkov

Good $daytime,

 Date: Wed, 25 Nov 1998 21:33:49 +0200
 From: Ibrahim Haddad [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Subject: remove from the list?

 can anyone tell me how to remove myself from this mailing list, please?

From welcome message:

| Welcome to the linux-c-programming mailing list!

| Please save this message for future reference.  Thank you.

| If you ever want to remove yourself from this mailing list,
| you can send mail to [EMAIL PROTECTED] with the following
| command in the body of your email message:

| unsubscribe linux-c-programming

| or from another account, besides [EMAIL PROTECTED]:

| unsubscribe linux-c-programming [EMAIL PROTECTED]

| If you ever need to get in contact with the owner of the list,
| (if you have trouble unsubscribing, or have questions about the
| list itself) send email to [EMAIL PROTECTED] .
| This is the general rule for most mailing lists when you need
| to contact a human.

|  Here's the general information for the list you've subscribed to,
|  in case you don't already have it:

| Linux C Programming Mailing List

  Regards,
  Willy.

--
"No easy hope or lies| Vitaly "Willy the Pooh" Fedrushkov
 Shall bring us to our goal, | Information Technology Division
 But iron sacrifice  | Chelyabinsk State University
 Of Body, Will and Soul."| mailto:[EMAIL PROTECTED]  +7 3512 156770
   R.Kipling | http://www.csu.ac.ru/~willy  VVF1-RIPE



Re: emacs problem

1998-10-28 Thread Vitaly Fedrushkov

Good $daytime,

 Date: Tue, 27 Oct 1998 15:23:17 +0800
 From: Song Lining [EMAIL PROTECTED]
 To: Linux C Programming List [EMAIL PROTECTED]
 Subject: emacs problem

 I've been trying to use emacs to edit my C++ code, and I've used M-x
 auto-fill-mode to turn on the autofill mode, when I want to insert some
 comment like /*asdfkj*/, it seemed not work at all, what's the problem?
 Could anyone tell me the exact actions I shall take?

Are you sure you're in C++ mode?  Second, wordwrap in ccmode somewhat
broken so that if you have no spaces in some comment line then you
won't get any subsequent lines filled.

BTW comments in C++ are mostly //, not /* */.

  Regards,
  Willy.

--
"No easy hope or lies| Vitaly "Willy the Pooh" Fedrushkov
 Shall bring us to our goal, | Information Technology Division
 But iron sacrifice  | Chelyabinsk State University
 Of Body, Will and Soul."| mailto:[EMAIL PROTECTED]  +7 3512 156770
   R.Kipling | http://www.csu.ac.ru/~willy  VVF1-RIPE



Re: mouse won't work

1998-10-12 Thread Vitaly Fedrushkov

Good $daytime,

 Date: Sat, 10 Oct 1998 06:48:33 PDT
 From: Shekhar Shenvikerkar [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Subject: mouse won't work

 I used the getmouse() function from the ncurses library.
 But the function is not working.
 Heard of the gpm server.But the man pages did not help.

1. What ncurses version you are running?  

2. Does it reproduce both in console and xterm?  Not all Linux
distributions have xterm or xterm-color running well with mouse.  Try
to use terminfo from latest ncurses.

3. Did you try to compile and run test/ncurses.c?  If it works, then
you probably have a bug in your code.

  Regards,
  Willy.

--
"No easy hope or lies| Vitaly "Willy the Pooh" Fedrushkov
 Shall bring us to our goal, | Information Technology Division
 But iron sacrifice  | Chelyabinsk State University
 Of Body, Will and Soul."| mailto:[EMAIL PROTECTED]  +7 3512 156770
   R.Kipling | http://www.csu.ac.ru/~willy  VVF1-RIPE



Re: C++ in Linux

1998-08-30 Thread Vitaly Fedrushkov

Good $daytime,

 Date: Sat, 29 Aug 1998 14:05:15 -0300
 From: Hernan Berinsky [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Subject: C++ in Linux

 =09I want to code in C++ with gcc (using cin, cout, classes,
 etc.), in Turbo C++ I include iostream.h, but I didn=B4t found it in
 /usr/include/..  How can I compile a C++ source?

Well,

| willy@snowyowl:~$ locate /iostream.h
| /mnt/dos/C/borlandc/include/iostream.h
| /usr/include/g++/iostream.h

As you can see, iostream.h is somewhere near, at least in my PC.  But
the proper compiler name for C++ is g++, not gcc.  Yes you _can_ do
this with gcc, but it does not look for ++ includes and libraries by
default.

Didn't you forget install C++ developmrnt libraries?

  Regards,
  Willy.

--
"No easy hope or lies| Vitaly "Willy the Pooh" Fedrushkov
 Shall bring us to our goal, | Information Technology Division
 But iron sacrifice  | Chelyabinsk State University
 Of Body, Will and Soul."| mailto:[EMAIL PROTECTED]  +7 3512 156770
   R.Kipling | http://www.csu.ac.ru/~willy  VVF1-RIPE