473,803 Members | 3,195 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 7404
Andrew Poelstra wrote:
On 2008-09-06, jacob navia <ja***@nospam.c omwrote:
>Richard Heathfield wrote:
>>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.
lcc-win solves this with the gc (garbage collector). This solution is
much more advanced than constructors/destructors since it allows you
to forget the accounting needed for each malloc() call.

Another solution is to do the following:

typedef struct tagString {
char *str; // data
size_t length; // used data
unsigned flags;
} String;

typedef struct tagStringToken {
int len; // number of strings
char *strArray[];
}

StringToken operator+(Strin g a,String b)

How would the compiler know to make a StringToken given the
context of two strings? What if you also had something like
The compiler doesn't know anything. It just applies the
operator + to a string and another string. Then, it sees
that the result is a thing called "StringToke n". It searches
for an overloaded operator of string + stringtoken and
finds one, then it applies it, until it sees the
assignment. It looks for an overloaded operator
assignment with at the LHS a String and the right
hand side a StringToken since that is the result of the
last addition. It finds one and then it applies that to the
two operands.
OtherString operator+(Strin g a, String b)

How would the compiler know what (string + string) should
evaluate to, a StringToken or an OtherString?
Because you told the compiler so by defining

StringToken operator+(Strin g,String);

Now the compiler knows that when it sees an addition
of a string to a string it should call the function
so defined.
Aside from that, this seems like a pretty elegant solution,
at least from the perspective of someone outside the black
box ;-)

<remainder snipped>

--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
Sep 6 '08 #161
Andrew Poelstra <ap*******@supe rnova.homewrite s:
[...]
Well, C strings are objects of type pointer-to-char,
[...]

No, a C string is "contiguous sequence of characters terminated by and
including the first null character". You're thinking of a "pointer to
a string", defined as "a pointer to its [the string's] initial (lowest
addressed) character". C99 7.1.1p1.

--
Keith Thompson (The_Other_Keit h) ks***@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"
Sep 6 '08 #162
Ian Collins <ia******@hotma il.comwrites:
[...]
C doesn't have strings. The solution would be to add them.
I presume that "C doesn't have strings" is a verbal shorthand for
something like "C doesn't have strings that can be conveniently
manipulated as first-class objects". C certainly does have strings;
see C99 7.1.1p1.

--
Keith Thompson (The_Other_Keit h) ks***@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"
Sep 6 '08 #163
jacob navia wrote:
Ian Collins wrote:
>jacob navia wrote:
>>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.
You know this to be false. You asked a question about this on c.l.c++.
>>This is done to support read only data types, what is very hard in C++.
Far from it, it is simple.

This is "simple" in C++ jargon, that I did not bother to
dig further.

It is not doable within the context we are discussing here.
So you can post something you know to be false but a correction is not
applicable?

If you had bothered to look beyond the end of your nose, you would have
found there is an idiomatic solution.

--
Ian Collins.
Sep 6 '08 #164
Keith Thompson wrote:
Ian Collins <ia******@hotma il.comwrites:
[...]
>C doesn't have strings. The solution would be to add them.

I presume that "C doesn't have strings" is a verbal shorthand for
something like "C doesn't have strings that can be conveniently
manipulated as first-class objects". C certainly does have strings;
see C99 7.1.1p1.
Well yes, the snipped context should have made that clear.

--
Ian Collins.
Sep 6 '08 #165
jacob navia wrote:
Richard wrote:
>I would sooner boil my nuts in a vat of sun flower oil than agree
that operator overloading in C is a good idea.

Should I send you olive oil maybe?
Ahh. The first real progress seen in this thread. :-)

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home .att.net>
Try the download section.
Sep 6 '08 #166
jacob navia <ja***@nospam.c omwrites:
[...]
lcc-win solves this with the gc (garbage collector). This solution is
much more advanced than constructors/destructors since it allows you
to forget the accounting needed for each malloc() call.
[...]

Garbage collection manages one resource, allocated memory.
Constructors and destructors can manage any arbitrary resource.
Admittedly memory is often the most important resource in a program,
but it's not always the only one.

--
Keith Thompson (The_Other_Keit h) ks***@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"
Sep 6 '08 #167
Ian Collins <ia******@hotma il.comwrites:
Keith Thompson wrote:
>Ian Collins <ia******@hotma il.comwrites:
[...]
>>C doesn't have strings. The solution would be to add them.

I presume that "C doesn't have strings" is a verbal shorthand for
something like "C doesn't have strings that can be conveniently
manipulated as first-class objects". C certainly does have strings;
see C99 7.1.1p1.
Well yes, the snipped context should have made that clear.
Well yes, but the on going game of "oneupsmans hip" played by the 3 or 4
main posters to c.l.c would be severely hampered if people actually
maintained context or allowed even slight discrepancies through in what
would, otherwise, be a perfectly understandable and helpful thread.

I dont think I was ever so confused as to what a string was until I saw
an explanation or two in this newsgroup ....
Sep 6 '08 #168
Malcolm McLean wrote:
"Nick Keighley" <ni************ ******@hotmail. comwrote:
>Telephone numbers suffer from the same problem. Hence London (UK)
got renumbered *twice* in recent years.

I'm of the opinon that 3074457345 telephones ought to be enough
for anyone, if 64 bit integers were distributed fairly instead
of being hogged by the rich nations.
However I have a strong suspicion that 18,446,744,073, 709,551,615
available URLs will suffice until the plague of humans
self-exterminates.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home .att.net>
Try the download section.
Sep 6 '08 #169
jacob navia wrote:
>
.... snip ...
>
The main application domain I see is the capacity of defining new
types of numerical data in C and keep the infix notation. You
can't argue that complicated fromula are more easily written
using the notation we learned at school.

It *is* easier to write
c = a+b
than c = sum(a,b);
Yes we can argue. In C (not C++), the function 'sum' will have
defined types and ranges for the arguments a and b, and will
produce a functional result according to some rules (totally
exposed by the code of 'sum'). Thus the results validity and value
is clearly defined. However, the '+' operator is already
overloaded, in that it can at least have byte, short, int, long,
float, double parameters, possibly mixed. Thus evaluating the
correctness of "c = a + b" requires careful consideration.

I consider the correctness and readability of a statement to be
more important than its terseness.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home .att.net>
Try the download section.
Sep 7 '08 #170

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

Similar topics

3
6559
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
6449
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
4275
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
9562
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
10542
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10309
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...
1
10289
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,...
1
7600
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
6840
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
5496
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
5625
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4274
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

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.