473,789 Members | 3,087 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

UNIX, C, Perl

Given that UNIX, including networking, is almost entirely coded in C,
how come so many things are almost impossible in ordinary C? Examples:
Network and internet access, access to UNIX interprocess controls and
communication, locale determination, EBCDIC/ASCII discrimination, etc.

Almost all of these are easy in Perl. Why isn't there a mechanism like
perl modules to allow easy extentions for facilities like these? Isn't
anyone working on this problem? or is it all being left for proprietary
systems?
Sep 2 '08
223 7384
jacob navia said:
Richard Heathfield wrote:
<snip>
Look Mr Heathfield, you know this by heart, and it is really not very
helpful to just play games and pose "clever" questions...
It wasn't a clever question. It was in fact a dumb question (but an honest
one), and it had an obvious answer, and having spent a few minutes
thinking about it I've answered it myself elsethread, in what I hope is a
positive way.
It would be *much* more helpful if you would help with the *real*
problems with this stuff...

(1) How do you overload the '[' ']' operators with multidimensiona l
arrays?
I wouldn't. I would allow any user-defined type to overload the array
operator, but I would stop there.

<snip>
(2)
How to overload the ++ operator to distinguish from pre-increment
and post increment?
I would propose
TYPE ++operator(TYPE s) // for pre-increment
TYPE operator++(TYPE s) // for post-increment
Those look fine to me.
>
but I am not sure of this.
Why not? What is your concern?
There are several open issues like those.
So bring them on.

--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Sep 6 '08 #141

"jacob navia" <ja***@nospam.c omwrote in message
(2)
How to overload the ++ operator to distinguish from pre-increment
and post increment?
I would propose
TYPE ++operator(TYPE s) // for pre-increment
TYPE operator++(TYPE s) // for post-increment
What a nightmare.

++obj will do something subtly different to obj++. I'd keep the C rules of
precedence and binding, and define that the operations are always identical
otherwise.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

Sep 6 '08 #142
Malcolm McLean said:
>
"jacob navia" <ja***@nospam.c omwrote in message
>(2)
How to overload the ++ operator to distinguish from pre-increment
and post increment?
I would propose
TYPE ++operator(TYPE s) // for pre-increment
TYPE operator++(TYPE s) // for post-increment
What a nightmare.

++obj will do something subtly different to obj++.
So what? It already does.

--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Sep 6 '08 #143
On Sep 6, 12:15*pm, Richard Heathfield <rj*@see.sig.in validwrote:
<snip>
>
No, because 'a' wouldn't be a simple pointer - it would need to be an
object (in the C sense at the very least) that contains a certain amount
of state, so I think we're going to need a destructor of some kind. Ah,
this is where the C++ pollution begins, I see.
It has little to do with C++. Wherever there are the concepts of
"object" and "state", there are the concepts of "constructo r" and
"destructor ". C is no exception.
but what about the intermediate strings?

You would handle those the same way you handle intermediate values in f = 1
+ 2 + 3 + 4 + 5 in current C.
The whole thing is very un-C-like.

Yes. It's beginning to look remarkably C++-like, though.
If by C++-like you mean modern, then yes :-)

Sebastian

Sep 6 '08 #144
s0****@gmail.co m writes:
On Sep 6, 12:15Â*pm, Richard Heathfield <rj*@see.sig.in validwrote:
<snip>
>>
No, because 'a' wouldn't be a simple pointer - it would need to be an
object (in the C sense at the very least) that contains a certain amount
of state, so I think we're going to need a destructor of some kind. Ah,
this is where the C++ pollution begins, I see.

It has little to do with C++. Wherever there are the concepts of
"object" and "state", there are the concepts of "constructo r" and
"destructor ". C is no exception.
but what about the intermediate strings?

You would handle those the same way you handle intermediate values in f = 1
+ 2 + 3 + 4 + 5 in current C.
The whole thing is very un-C-like.

Yes. It's beginning to look remarkably C++-like, though.

If by C++-like you mean modern, then yes :-)

Sebastian
RH knew exactly which way the conversation would turn. It is foolish to
pretend the addition of overloaded operators in C will not turn C into a
"poor mans" C++.
Sep 6 '08 #145
s0****@gmail.co m said:
On Sep 6, 12:15 pm, Richard Heathfield <rj*@see.sig.in validwrote:
<snip>
>>
No, because 'a' wouldn't be a simple pointer - it would need to be an
object (in the C sense at the very least) that contains a certain amount
of state, so I think we're going to need a destructor of some kind. Ah,
this is where the C++ pollution begins, I see.

It has little to do with C++. Wherever there are the concepts of
"object" and "state", there are the concepts of "constructo r" and
"destructor ". C is no exception.
I already use constructors and destructors in C, so I know what you mean,
but it isn't quite what /I/ meant. In C, I have to call constructors and
destructors explicitly, and I'm fine with that. But if ISO were to
introduce operator overloading into C, I think there would be a lot of
pressure to introduce automatically-invoked constructors and destructors,
because (so it seems to me) there would be much more cleanup to do than is
at present the case, and the cost of overlooking cleanup could become
arbitrarily high.
but what about the intermediate strings?

You would handle those the same way you handle intermediate values in f
= 1 + 2 + 3 + 4 + 5 in current C.
The whole thing is very un-C-like.

Yes. It's beginning to look remarkably C++-like, though.

If by C++-like you mean modern, then yes :-)
No, I don't mean that. C is just about as modern as C++ is. It's just
*different*. Adding operator overloading would make it slightly less
different, and adding constructors and destructors would make it slightly
less different still, but that wouldn't make it any more "modern".

--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Sep 6 '08 #146
Richard Heathfield wrote:
>(1) How do you overload the '[' ']' operators with multidimensiona l
arrays?

I wouldn't. I would allow any user-defined type to overload the array
operator, but I would stop there.
But why? I do not see any reason (besides C++ compatibility) to avoid
overloading n dimensional arrays.
<snip>
>(2)
How to overload the ++ operator to distinguish from pre-increment
and post increment?
I would propose
TYPE ++operator(TYPE s) // for pre-increment
TYPE operator++(TYPE s) // for post-increment

Those look fine to me.
OK
>
> but I am not sure of this.

Why not? What is your concern?
>There are several open issues like those.

So bring them on.
I think it is important to distinguish between read
and write access to tables. I use

TYPE operator [ ]=(TYPE table, int idx, ELEMENT_TYPE newvalue)
This would apply to

table[idx] = newvalue;

In C++ there is no way to distinguish between those
operations since you just return a pointer.

This is done to support read only data types, what is very hard in C++.

I will bring other issues later.

--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
Sep 6 '08 #147
Richard Heathfield <rj*@see.sig.in validwrites:
s0****@gmail.co m said:
>On Sep 6, 12:15 pm, Richard Heathfield <rj*@see.sig.in validwrote:
<snip>
>>>
No, because 'a' wouldn't be a simple pointer - it would need to be an
object (in the C sense at the very least) that contains a certain amount
of state, so I think we're going to need a destructor of some kind. Ah,
this is where the C++ pollution begins, I see.

It has little to do with C++. Wherever there are the concepts of
"object" and "state", there are the concepts of "constructo r" and
"destructor" . C is no exception.

I already use constructors and destructors in C, so I know what you mean,
but it isn't quite what /I/ meant. In C, I have to call constructors and
destructors explicitly, and I'm fine with that. But if ISO were to
introduce operator overloading into C, I think there would be a lot of
pressure to introduce automatically-invoked constructors and destructors,
because (so it seems to me) there would be much more cleanup to do than is
at present the case, and the cost of overlooking cleanup could become
arbitrarily high.
>but what about the intermediate strings?

You would handle those the same way you handle intermediate values in f
= 1 + 2 + 3 + 4 + 5 in current C.

The whole thing is very un-C-like.

Yes. It's beginning to look remarkably C++-like, though.

If by C++-like you mean modern, then yes :-)

No, I don't mean that. C is just about as modern as C++ is. It's just
*different*. Adding operator overloading would make it slightly less
different, and adding constructors and destructors would make it slightly
less different still, but that wouldn't make it any more "modern".
That last paragraph is complete and utter rubbish and I have no idea why
someone with your technical knowledge and skills would say such a
thing. Note that "modern" does not, in any way, indicate "improved" as
far as the end product goes but there is a LOT of modern OO thinking
that has gone into C++.

Sep 6 '08 #148
jacob navia said:
Richard Heathfield wrote:
>>(1) How do you overload the '[' ']' operators with multidimensiona l
arrays?

I wouldn't. I would allow any user-defined type to overload the array
operator, but I would stop there.

But why? I do not see any reason (besides C++ compatibility) to avoid
overloading n dimensional arrays.
If you really want to do it, I suppose one way would be to allow type
synonyms to have their operators overloaded too. So, for example, here is
a not-very-well-thought-out idea in a language only barely resembling C:

struct foo
{
int i;
int j;
};

int foo::operator[](int offset) { return offset==0 ? i : j; }

/* yes, I stole the s.r.o. from C++ - sorry about that, but it conveys the
idea better than any other way I could think of */

typedef struct foo bar[]; /* bar is a synonym for an array of foo
with an arbitrary number of members */

int bar::operator[](int offset) { whatever...

the idea being that any given type can only overload one level of array
operator, but you add the ability to "build up" array types, dimension by
dimension, using typedef, and you give these array types the ability to
overload /their/ array operator. That would give you as many dimensions as
you need.

The more I think about this, the more I think it belongs in
comp.programmin g, not comp.lang.c. Still, at least it /is/ a discussion
now, which is a good start.

--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Sep 6 '08 #149
On 2008-09-06, Malcolm McLean <re*******@btin ternet.comwrote :
>
"jacob navia" <ja***@nospam.c omwrote in message
>(2)
How to overload the ++ operator to distinguish from pre-increment
and post increment?
I would propose
TYPE ++operator(TYPE s) // for pre-increment
TYPE operator++(TYPE s) // for post-increment
What a nightmare.

++obj will do something subtly different to obj++. I'd keep the C rules of
precedence and binding, and define that the operations are always identical
otherwise.
ITYM, only one ++ behavior should be defined, and when it is invoked as
++obj, the value returned will be that /after/ said behavior, and when
invoked as obj++, the original object should be returned.

I'm not sure 'precedence' and 'binding' are the correct terms for that.

--
Andrew Poelstra ap*******@wpsof tware.com
To email me, use the above email addresss with .com set to .net
Sep 6 '08 #150

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

Similar topics

3
6557
by: dpackwood | last post by:
Hello, I have two different scripts that do pretty much the same thing. The main perl script is on Windows. It runs and in the middle of it, it then calls out another perl script that then should run on a Unix box I have. Both scripts run ok, except for the part when Windows try's to call out the Unix script. I have it set up where the Unix is mapped through a drive letter and can drop stuff into the Unix box. It is going through another...
2
5673
by: Mohsin | last post by:
Hi all, I have a perl program which makes a user exit to the O/S (unix, solaris) to issue a O/S command. I know that the shell it invokes is NOT a korn shell, because I captured the shell info into a file with a 'ps' command. My question is "How to explicitly specify a Korn shell to be used by perl?" Eg of my perl code: ## Begin code snippet..
0
6448
by: Danny Jensen | last post by:
I need to test if certain processes on a unix box were running. I wanted to use whatsup gold to do the testing. First I needed to go to the whatsup configure>monitors & services menu to add this tcp/ip port 1555 service with the folowing lines: Send=psef /dj/myco/rf.monitor\r\n Expect=~1 the psef above is a command that the unix server executes. The unix box communicates back a 1 if the test is successful and a 0 if it is
1
17721
by: Al Belden | last post by:
Hi all, I've been working on a problem that I thought might be of interest: I'm trying to replace some korn shell scripts that search source code files with perl scripts to gain certain features such as: More powerful regular expressions available in perl Ability to print out lines before and after matches (gnu grep supports this but is not availble on our Digital Unix and AIX platforms) Make searches case insensitive by default (yes, I...
6
1671
by: asimorio | last post by:
Hi folks, Recently, I am investigatin a memory leak issue. I have written a simple C++ program and a Perl script to test on UNIX environment machine. I do a for loop to new up 20 char of size 32768 bytes, then delete them. Please see below: //// part of the code start //// for (i=0; i<20; i++) { ptrA = new (std::nothrow) char;
2
4275
by: perlnewbie | last post by:
Hi everyone I am new to perl and I am writing a perl script to invoke a set of commands on UNIX clearcase vob however I am having trouble after setting the view and mounting the vob I want to change the directory into the vob and then using Cwd or pwd to confirm I am in the vob to continue the CC functions. Sample code in perl : $Result = system 'cleartool setview admin_view'; $Result = system ('cleartool mount /vobs/test');
4
3792
by: jane007 | last post by:
Hello everybody: I am having a problem. On Unix platform, there is a script that need user to input data from console, then when I call Unix perl script from Windows, these is an issue occurs, when I input data and enter "enter" so fast, the Windows console is freezed, I don't know why, does anybody know?Thank you very much. My code like follows:
4
4274
by: mdshafi01 | last post by:
Hi , I am trying to send mail from unix perl. I am using following code to send mail. It is not triggering mail and also it is not giving any error. please tell me any special settings are required or this program should be executed from special user with higher permission or something. please tell me.
1
3983
by: dxz | last post by:
I have a perl script to run on both UNIX and Windows. How should I write the Shabang line: On UNIX, it is #!/usr/bin/perl On Windows, it is #!C:\perl\bin\perl.exe Which one should I use? Should I combine them? If yes, how?
0
9665
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
10408
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...
1
10139
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9983
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
9020
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...
1
7529
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5417
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
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2909
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.