473,783 Members | 2,545 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Interesting code

Happened to see my old (last millennium) c code. Almost forgot that I
wrote it .
It is interesting. :-)

int sqrt(int no)
{
int t;
no = t * t;
return t;
}

Nov 16 '06
26 3650
In article <11************ **********@h54g 2000cwb.googleg roups.com"=?utf-8?B?SGFyYWxkIHZ hbiBExLNr?=" <tr*****@gmail. comwrites:
Richard Bos wrote:
August Karlstrom <fu********@com hem.sewrote:
....
I'd say: "...hasn't been exposed to C's unfortunate choice of symbol for
assignment". ;-)
You could say that, but don't more than half of all programming
languages which are used in practice (i.e., Intercal and Plankalkuel
don't count) share that choice of symbol?

How many of those have copied their operators from C?
I would rather say that C has copied it from other languages (the use
of '=' for assignment). I think Fortran was the first.
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Nov 23 '06 #21
In article <Si************ ******@newsb.te lia.netAugust Karlstrom <fu********@com hem.sewrites:
....
Mathematics Pascal/Modula/Oberon C
x = y x equals y x equals y x becomes y
1/2 0.5 0.5 0
The second line is incorrect for Mathematics if you are not working in
the reals.
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Nov 23 '06 #22
CBFalconer wrote:
Harald van D?k wrote:
Richard Bos wrote:
August Karlstrom <fu********@com hem.sewrote:
Keith Thompson skrev:

To someone who knows what "=" means in mathematics, but hasn't
been exposed to the concept of assignment, it's not an entirely
insane misconception.

I'd say: "...hasn't been exposed to C's unfortunate choice of
symbol for assignment". ;-)

You could say that, but don't more than half of all programming
languages which are used in practice (i.e., Intercal and
Plankalkuel don't count) share that choice of symbol?
How many of those have copied their operators from C?

Which in turn copied its silly assignment operator from Fortran.
Or more directly, from B, I imagine. But where C got it from is not
really relevant to my point.

Nov 24 '06 #23
Dear Mr Richard.. I asked out of curiosity to vijayakumar ..

And he might have got it that the question was meant to him.

Richard Heathfield wrote:
Dh*********@gma il.com top-posted, but I've fixed that. He said:
v4vijayakumar wrote:
Happened to see my old (last millennium) c code. Almost forgot that I
wrote it .
It is interesting. :-)

int sqrt(int no)
{
int t;
no = t * t;
return t;
}
Can u tell me what is interesting in this code ??

No, there isn't any regular comp.lang.c contributor called "u".
(Translation: abbreviating "you" to "u" marks you out as someone who can't
even spell "you" properly. Take the time to type "you" in full, in the
interests of clear communication and of not looking idiotic.)

Here are the principal points of interest:

1) function name choice invades implementation namespace, thus invoking
undefined behaviour;
2) function name choice gives a misleading impression of what the function
tries to do;
3) t's value is indeterminate, but the function still attempts to use t's
value regardless, thus invoking undefined behaviour;
4) a parameter is used solely for assigning a value to, and this value will
be lost at the same time that the parameter itself is lost, at the end of
this function;
5) an indeterminate value is returned from this function, thus invoking
undefined behaviour in any caller that evaluates it;
6) even if all those faults were fixed, the function would still need major
repair work (type choices, range validation, etc).

Summary: it was written by someone who didn't know C very well six or seven
years ago. Whether they have learned their lessons in the meantime, I
cannot say.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: normal service will be restored as soon as possible. Please do not
adjust your email clients.
Nov 24 '06 #24
Dh*********@gma il.com said:
Dear Mr Richard.. I asked out of curiosity to vijayakumar ..

And he might have got it that the question was meant to him.
If you wish to direct a communication to a specific individual, I recommend
email as the best medium. The comp.lang.c newsgroup is an international
newsgroup, not a private bulletin board.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Nov 24 '06 #25
Dik T. Winter skrev:
In article <Si************ ******@newsb.te lia.netAugust Karlstrom <fu********@com hem.sewrites:
...
Mathematics Pascal/Modula/Oberon C
x = y x equals y x equals y x becomes y
1/2 0.5 0.5 0

The second line is incorrect for Mathematics if you are not working in
the reals.
Well, it's just as valid for the rational numbers (Q is a field).

In the ring of integers, division is not defined for every number (not
every integer has a multiplicative inverse).
August

--
"Programmin g languages like C make people really believe that one half
equals zero." -- A. Karlstrom
Nov 25 '06 #26
In article <Vx************ ******@newsb.te lia.netAugust Karlstrom <fu********@com hem.sewrites:
Dik T. Winter skrev:
In article <Si************ ******@newsb.te lia.netAugust Karlstrom <fu********@com hem.sewrites:
...
Mathematics Pascal/Modula/Oberon C
x = y x equals y x equals y x becomes y
1/2 0.5 0.5 0
The second line is incorrect for Mathematics if you are not working in
the reals.

Well, it's just as valid for the rational numbers (Q is a field).

In the ring of integers, division is not defined for every number (not
every integer has a multiplicative inverse).
So, C defines division in the integers (as the truncating variant). What
is wrong with that? But, whatever, both semantics above of '=' and '/'
are indirectly from Fortran. You should know the off-spring of programming
languages to understand that. Algol 58 (never really defined) took it from
Fortran. And Algol 58 begot Jovial, which begot CPL, which begot BCPL,
which begot B, which begot C. Algol 58 also begot Algol 60 (which changed
use), which in turn begot Pascal/Modula/Oberon. And the very first
assembly language I did learn also used '=' for assignment:
S = M[A]
which meant: fetch the contents of memory location A and store it in
register S. To get the condition bit set when the two were equal you
used:
U, S - M[A], Z
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Nov 26 '06 #27

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

Similar topics

8
1678
by: Bruno R. Dias | last post by:
Perhaps it would be interesting to program a virtual machine simulating an ancient computer (such as the pdp-7). Then, it would be rather interesting to code for it (porting gcc to it maybe?). I think it would be fun to play with the long-forgotten art of coding in machine language. And what about a fictional computer, such as one that works on an entirely different way (such as a non-binary computer)? It wouldn't be very useful, but...
2
4938
by: Dylan Phillips | last post by:
A strang error is occurring when I run the following code: SqlConnection c = new SqlConnection(); c.ConnectionString = "Initial Catalog=Northwind;user id=sa;password=kat1ie;Data Source=server"; c.Open(); SqlCommand command = c.CreateCommand(); command.CommandType = CommandType.Text; command.CommandText = "select Customers.customerid, customers.companyname, " +
6
3905
by: Claude Yih | last post by:
Hi, everyone. I noticed an interesting thing about fread() this afternoon. Well, I can't see why so I post this message in the hope of getting some explanation. Please help me. I wrote the following code in Windows 2k and compiled it with the gcc(version: 3.2.3) contained in MinGW: #include <stdio.h> #include <stdlib.h> #include <string.h>
23
1191
by: Mythran | last post by:
For i As Integer = 0 To 5 Dim sb As StringBuilder If i = 0 sb = New StringBuilder(i.ToString()) Next i Console.WriteLine(sb.ToString()) Next i The above code gives the following output:
2
2103
by: sasifiqbal | last post by:
Hi, One of my developers are facing an interesting problem regarding UserControl invalidation. The problem is: We have two forms in our application. Form A does nothing except loading of Form B and Form B contains an array of UserButton kind of contol (we have created our own buttons deriving from UserButton). All the drawings activities in Form B are okay and nothing gets wrong if we
8
7994
by: Mythran | last post by:
Here is some code the provides some really interesting results! First, read over the two methods in class 'A' and compare. Just by looking at them, both results appear to return the EXACT same information the same way. But the appearances are deceiving! Copy and paste into a console application, then set the configuration to Release mode :) using System; using System.Diagnostics; using System.Reflection;
27
2340
by: Frederick Gotham | last post by:
I thought it might be interesting to share experiences of tracking down a subtle or mysterious bug. I myself haven't much experience with tracking down bugs, but there's one in particular which comes to mind. I was writing usable which dealt with strings. As per usual with my code, I made it efficient to the extreme. One thing I did was replace, where possible, any usages of "strlen" with something like: struct PtrAndLen { char *p;
12
4491
by: Daniel Earwicker | last post by:
I wrote two trivial test programs that do a billion iterations of a virtual method call, first in C# (Visual Studio 2005): Thing t = new DerivedThing(); for (System.Int64 n = 0; n < 10000000000; n++) t.method(); Then in C++ (using Visual C++ 2005): Thing *t = new DerivedThing();
0
9480
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
10315
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
10083
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
8968
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
7494
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
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4044
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
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2877
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.