Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Convert VB code to C code.

1 view
Skip to first unread message

Kenneth Osenbroch

unread,
Nov 2, 2004, 4:01:06 PM11/2/04
to
Hi,

I am having trouble translating the following lines of Visual Basic
code to C.

For iCounter = Len(sReference) To 1 Step -1
iSum = iSum + Val(Mid(sReference, iCounter, 1)) * iMultiplier
Next

fReferenceCheckSum = Right(Str(10 - (iSum Mod 10)), 1)

Any ideas anyone? I have had some help, but I need to know how C's FOR
loops looks like, and how "Val(Mid.." and "Right(Str..." are
translated into C. Any further help would be greatly appreciated.

Thanks,
Kenneth

Dave Vandervies

unread,
Nov 2, 2004, 4:27:19 PM11/2/04
to
Hmm. Interesting, yet oddly not inappropriate, crosspost list on
this one.

In article <ce7df6a2.04110...@posting.google.com>,


Kenneth Osenbroch <kenneth....@telenor.com> wrote:
>Hi,
>
>I am having trouble translating the following lines of Visual Basic
>code to C.
>
> For iCounter = Len(sReference) To 1 Step -1
> iSum = iSum + Val(Mid(sReference, iCounter, 1)) * iMultiplier
> Next
>
> fReferenceCheckSum = Right(Str(10 - (iSum Mod 10)), 1)
>
>Any ideas anyone? I have had some help, but I need to know how C's FOR
>loops looks like,

You'll want to get a textbook (or somebody who knows C) for this.
Get a basic knowledge of the language, and *then* start translating code
into it.

Be careful choosing textbooks, because there are a lot of bad ones
out there. One of the best, especially if you've done some programming
in other languages, is _The C Programming Language, 2nd edition_ by
Kernighan and Ritchie.


> and how "Val(Mid.." and "Right(Str..." are
>translated into C.

If I'm remembering my misspent youth with the Commodore 64 correctly,
and if VB has inherited them (from there or from a common source) without
too many changes (or if my misremembering and VB's embrace-and-extend have
modified them in similar ways), Val converts a string into a numeric value
and Right takes the last N characters of a string. (The code snippet here
also uses Mid, which takes a substring out of the middle of a string.)

If that's incorrect, I'm sure we'll be hearing about it from somebody
in the VB newsgroup.

Look up sscanf for converting strings into numeric values.

Strings in C are just arrays of characters, so you can handle substring
operations by copying the appropriate set of characters into another
buffer and terminating it appropriately. Be careful with what goes
where; you need to do all the memory management yourself, which bites
people coming from Basic-ish backgrounds with great predictability.


dave

--
Dave Vandervies dj3v...@csclub.uwaterloo.ca
He should have done something similar to what I did last week. I broke into
his house when it was empty and turned the toilet roll around the wrong way.
--Bill Godfrey in comp.lang.c

CBFalconer

unread,
Nov 2, 2004, 5:50:40 PM11/2/04
to

Here in c.l.c we have no idea what those functions do. However I
can give you a C equivalent of the for statement:

for (iCounter = Len(...); /* initialization */
iCounter >= 1; /* continue condition */
iCounter--) /* loop alteration action */
{
/* whatever that funny statement does */
}

but lose the ugly hungarian notation.

--
Chuck F (cbfal...@yahoo.com) (cbfal...@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!


cr88192

unread,
Nov 2, 2004, 9:07:02 PM11/2/04
to

"Kenneth Osenbroch" <kenneth....@telenor.com> wrote in message
news:ce7df6a2.04110...@posting.google.com...

I think (mind you c's arrays are 0 based, and I don't know vb):
for(iCounter=strlen(sReference); iCounter>0; iCounter--)
iSum+=atoi(sReference[i-1])*iMultiplier;

//buf is added here as a string buffer
sprintf(buf, "%d", 10-(iSum%10));
fReferenceChecksum=atoi(buf[strlen(buf)-1]);

this is just a guess (I would think the last one would have suffered from a
type error, but afaik vb can also insert implicit coercions).

cr88192

unread,
Nov 2, 2004, 11:07:50 PM11/2/04
to

"cr88192" <cr8...@remove.hotmail.com> wrote in message
news:a3Xhd.268$l66...@news.flashnewsgroups.com...

>
> "Kenneth Osenbroch" <kenneth....@telenor.com> wrote in message
> news:ce7df6a2.04110...@posting.google.com...
>> Hi,
>>
>> I am having trouble translating the following lines of Visual Basic
>> code to C.
>>
>> For iCounter = Len(sReference) To 1 Step -1
>> iSum = iSum + Val(Mid(sReference, iCounter, 1)) * iMultiplier
>> Next
>>
>> fReferenceCheckSum = Right(Str(10 - (iSum Mod 10)), 1)
>>
>> Any ideas anyone? I have had some help, but I need to know how C's FOR
>> loops looks like, and how "Val(Mid.." and "Right(Str..." are
>> translated into C. Any further help would be greatly appreciated.
>>
>
> I think (mind you c's arrays are 0 based, and I don't know vb):
> for(iCounter=strlen(sReference); iCounter>0; iCounter--)
> iSum+=atoi(sReference[i-1])*iMultiplier;
>
> //buf is added here as a string buffer
> sprintf(buf, "%d", 10-(iSum%10));
> fReferenceChecksum=atoi(buf[strlen(buf)-1]);
>
and, in being distracted, made an obvious error:
fReferenceChecksum=atoi(&buf[strlen(buf)-1]);

or:
fReferenceChecksum=atoi(buf+(strlen(buf)-1));

Frank Adam

unread,
Nov 3, 2004, 12:37:20 AM11/3/04
to
On 2 Nov 2004 13:01:06 -0800, kenneth....@telenor.com (Kenneth
Osenbroch) wrote:

Kenneth, i didn't know that you didn't know about C. I thought you
didn't know about VB, but now i just don't know which one you don't
know about ? ;-p

Perhaps my using a pointer to iterate through the string, threw you ?
Although, on reread, i was going through the string forward, not
backwards, so that may have played some part if it didn't work, or
maybe i was just plain cold sober.. but TBH, i did expect that you can
adjust that code as needed.

What exactly is this for ? Is this a school project, or do you want it
to just get the VB code to work in C ?
If it's just a conversion, then lose the iterator and the for-next and
use a pointer to go through the string. It's much cleaner.

Anyway, the "for-next" in C is :
for( counter = start; counter > 1; counter--)
where 'start' in your case would be strlen(sReference) or in VB
Len(sReference).

Val(string) in VB returns the numeric value of a String. ie: "48"
yields 48 as a value, not to be confused with Ascii 48 which is 0. :)
In C, you can do that with atoi(buffer).
value = atoi(buffer);

Mid(buffer, start, length) picks out 'length' number of characters
from 'buffer', starting at 'start'
In C, that can be done with strncpy(), sprintf() etc...

It could be made up like this :

char* mid(buffer, start, len)
{
char *p, *ret;
if (NULL != buffer)
{
/* should check for len and start being ok..but bugger it */
p = &buffer[start];
ret = malloc(sizeof(char) * len + 1);
if (NULL != ret)
{
strcnpy(ret,p,len);
ret[len] = '\0' /* don't remember if it terms or not */
}
}
return ret;
}


Right$(buffer, length) returns the rightmost 'length' characters from
'buffer'.
A C version may be :

char* Right(char* buffer,long len)
{
char* p = buffer, long blen;

if(NULL != p)
{
blen = strlen(p);
if (len < strlen(p))
p = &buffer[blen - len];
}
return p;
}
--

Regards, Frank

Frank Adam

unread,
Nov 3, 2004, 12:49:19 AM11/3/04
to
On Wed, 03 Nov 2004 16:37:20 +1100, fa...@xxxxoptushome.com.au (Frank
Adam) wrote:

> char* mid(buffer, start, len)
>
This should have read :
char* mid(char* buffer, size_t start, size_t len)

>char* Right(char* buffer,long len)
>
And this being x-posted to C.L.C. i should have remembered to use
size_t instead of longs. I'm slapping my hands as we speak.. :)

--

Regards, Frank

Richard Bos

unread,
Nov 3, 2004, 11:12:24 AM11/3/04
to
"cr88192" <cr8...@remove.hotmail.com> wrote:

> "Kenneth Osenbroch" <kenneth....@telenor.com> wrote in message
> news:ce7df6a2.04110...@posting.google.com...

> > I am having trouble translating the following lines of Visual Basic
> > code to C.
> >
> > For iCounter = Len(sReference) To 1 Step -1
> > iSum = iSum + Val(Mid(sReference, iCounter, 1)) * iMultiplier
> > Next
> >
> > fReferenceCheckSum = Right(Str(10 - (iSum Mod 10)), 1)

> I think (mind you c's arrays are 0 based, and I don't know vb):


> for(iCounter=strlen(sReference); iCounter>0; iCounter--)
> iSum+=atoi(sReference[i-1])*iMultiplier;

Several mistakes here.

First of all, atoi() is not the function of choice. If sReference
contains an value which isn't representable in int, it causes undefined
behaviour. Use strtol() instead; it doesn't have this problem, and is
more flexible, too. For example, it can be used to detect errors which
the Basic code doesn't even check for.

Second, note that the length parameter to both Mid() and Right() is 1,
meaning that the Basic code handles single characters. This makes the C
equivalent simpler than one would expect:

for (counter = strlen(sReference)-1; counter>=0; counter--)
iSum += (sReference[counter]-'0') * iMultiplier;

Note: no function calls except strlen(). Neither atoi() nor strtol() is
even necessary. And since all members of the string are worth the same
amount and their order doesn't matter, even strlen() can be eliminated:

for (counter=0; sReference[counter]; counter++)
iSum += (sReference[counter]-'0') * iMultiplier;

Of course, the equivalent using pointers is just as valid.

[ Next line copied here for easier reference ]


> > fReferenceCheckSum = Right(Str(10 - (iSum Mod 10)), 1)

> //buf is added here as a string buffer


> sprintf(buf, "%d", 10-(iSum%10));
> fReferenceChecksum=atoi(buf[strlen(buf)-1]);

The extra buffer is unnecessary. Note, again, the single character used
to determine the end result. (Also, your version results in an int,
while the Basic code gives a one-character string.)

fReferenceCheckSum = 10-iSum%10 + '0';

That simple. Unless you want a string instead of a single char, in which
case fReferenceCheckSum (what _is_ it with M$ programmers and
sesquipedalian identifiers, anyway?) needs to be at least a char[2], not
a char, and you need to write

fReferenceCheckSum[0]=10-iSum%10 + '0';
fReferenceCheckSum[1]='\0';

Richard

cr88192

unread,
Nov 3, 2004, 12:33:36 PM11/3/04
to

"Richard Bos" <r...@hoekstra-uitgeverij.nl> wrote in message
news:4188fedc....@news.individual.net...

> "cr88192" <cr8...@remove.hotmail.com> wrote:
>
>> "Kenneth Osenbroch" <kenneth....@telenor.com> wrote in message
>> news:ce7df6a2.04110...@posting.google.com...
>> > I am having trouble translating the following lines of Visual Basic
>> > code to C.
>> >
>> > For iCounter = Len(sReference) To 1 Step -1
>> > iSum = iSum + Val(Mid(sReference, iCounter, 1)) * iMultiplier
>> > Next
>> >
>> > fReferenceCheckSum = Right(Str(10 - (iSum Mod 10)), 1)
>
>> I think (mind you c's arrays are 0 based, and I don't know vb):
>> for(iCounter=strlen(sReference); iCounter>0; iCounter--)
>> iSum+=atoi(sReference[i-1])*iMultiplier;
>
> Several mistakes here.
>
yes, it seems there were a lot.
in my distraction of trying to understand the original code, it seems I
forgot, eg, how to use strings, or much else for that matter...

those fragments are emberassing, they make me look like some stupid
newbie...

> First of all, atoi() is not the function of choice. If sReference
> contains an value which isn't representable in int, it causes undefined
> behaviour. Use strtol() instead; it doesn't have this problem, and is
> more flexible, too. For example, it can be used to detect errors which
> the Basic code doesn't even check for.
>

I usually use my own version as the standard version, eg, has problems
dealing with things like '0x...' in many cases.

> Second, note that the length parameter to both Mid() and Right() is 1,
> meaning that the Basic code handles single characters. This makes the C
> equivalent simpler than one would expect:
>
> for (counter = strlen(sReference)-1; counter>=0; counter--)
> iSum += (sReference[counter]-'0') * iMultiplier;
>

one could do that...

> Note: no function calls except strlen(). Neither atoi() nor strtol() is
> even necessary. And since all members of the string are worth the same
> amount and their order doesn't matter, even strlen() can be eliminated:
>
> for (counter=0; sReference[counter]; counter++)
> iSum += (sReference[counter]-'0') * iMultiplier;
>

yes, possible.
however, in this case the op may no longer recognize the algo?...

> Of course, the equivalent using pointers is just as valid.
>

agreed.

> [ Next line copied here for easier reference ]
>> > fReferenceCheckSum = Right(Str(10 - (iSum Mod 10)), 1)
>
>> //buf is added here as a string buffer
>> sprintf(buf, "%d", 10-(iSum%10));
>> fReferenceChecksum=atoi(buf[strlen(buf)-1]);
>
> The extra buffer is unnecessary. Note, again, the single character used
> to determine the end result. (Also, your version results in an int,
> while the Basic code gives a one-character string.)
>

yes, I had failed to take into account that printing a value 0..9 in decimal
and taking the last digit is equivalent to just using the value.

> fReferenceCheckSum = 10-iSum%10 + '0';
>

I was confused as to what was going on with that...
of course, this looks dubious as well.

> That simple. Unless you want a string instead of a single char, in which
> case fReferenceCheckSum (what _is_ it with M$ programmers and
> sesquipedalian identifiers, anyway?) needs to be at least a char[2], not
> a char, and you need to write
>
> fReferenceCheckSum[0]=10-iSum%10 + '0';
> fReferenceCheckSum[1]='\0';
>

dunno, 'f' makes me think 'float', but I don't know what type the op was
using...

Alex Fraser

unread,
Nov 3, 2004, 11:32:04 PM11/3/04
to
"Richard Bos" <r...@hoekstra-uitgeverij.nl> wrote in message
news:4188fedc....@news.individual.net...
> [ Next line copied here for easier reference ]
> > > fReferenceCheckSum = Right(Str(10 - (iSum Mod 10)), 1)
>
> fReferenceCheckSum = 10-iSum%10 + '0';

This is not equivalent if iSum % 10 is zero (produces '0' + 10 instead of
'0'). Instead:

fReferenceCheckSum = (10 - iSum % 10) % 10 + '0';

Perhaps better, put a "% 10" inside the loop instead of the first one above
and almost arbitrary length "number strings" (I guess: barcodes) will work.

Alex


anony*mouse

unread,
Nov 4, 2004, 12:59:27 AM11/4/04
to
kenneth....@telenor.com (Kenneth Osenbroch) wrote in message news:<ce7df6a2.04110...@posting.google.com>...

>
> I am having trouble translating the following lines of Visual Basic
> code to C.
>
> For iCounter = Len(sReference) To 1 Step -1
> iSum = iSum + Val(Mid(sReference, iCounter, 1)) * iMultiplier
> Next
>
> fReferenceCheckSum = Right(Str(10 - (iSum Mod 10)), 1)
>
> Any ideas anyone?

[code]
#include <stdio.h>
#include <ctype.h>

int main(void)
{
const char* sReference = "12dgh3456";
const int iMultiplier = 11;

float fReferenceCheckSum;
int iSum = 0;
int iCounter = strlen(sReference);

while (--iCounter >= 0)
{
iSum += isdigit(sReference[iCounter]) ?
(sReference[iCounter] - '0') * iMultiplier : 0;
}

fReferenceCheckSum = (float) ((10 - (iSum % 10)) % 10);

printf("fReferenceCheckSum = %.0f, iSum = %d",
fReferenceCheckSum, iSum);

getchar();
return 0;
}
[/code]

---
Note: My reply address is invalid.

MJSR

unread,
Nov 4, 2004, 10:12:44 AM11/4/04
to
r...@hoekstra-uitgeverij.nl (Richard Bos) wrote in message news:<4188fedc....@news.individual.net>...

> "cr88192" <cr8...@remove.hotmail.com> wrote:
>
> > "Kenneth Osenbroch" <kenneth....@telenor.com> wrote in message
> > news:ce7df6a2.04110...@posting.google.com...
> [ Next line copied here for easier reference ]
> > > fReferenceCheckSum = Right(Str(10 - (iSum Mod 10)), 1)
>
> > //buf is added here as a string buffer
> > sprintf(buf, "%d", 10-(iSum%10));
> > fReferenceChecksum=atoi(buf[strlen(buf)-1]);
>
> The extra buffer is unnecessary. Note, again, the single character used
> to determine the end result. (Also, your version results in an int,
> while the Basic code gives a one-character string.)
>
> fReferenceCheckSum = 10-iSum%10 + '0';

Somebody has already pointed out that this would be wrong if
iSum%10 is zero. One would have to examine the declaration of
fReferenceCheckSum (or its later usage) to determine the correct
C; strings are automatically converted to numbers in VB (at least,
in my experience) and characters are represented as strings with
length one. So
fReferenceCheckSum = (10-iSum%10)%10;
would be correct if fReferenceCheckSum is a numeric variable.

--
MJSR

John Smith

unread,
Nov 5, 2004, 12:55:56 PM11/5/04
to
Kenneth Osenbroch wrote:

Standard C library doesn't have a function comparable to VB's mid(),
left() and right(). Here is a homegrown C function similar to mid():

/* midstr returns a substring of n
characters of str starting at s,
or remaining characters of string
if s+n exceeds the length of str.
*/
char* midstr(char* str, int s, int n)
{
int idx, jdx, len;
char* mid;

jdx = 0;
len = 0;
while(str[jdx++] != '\0')
++len;
if(s + n > len)
n = len - s;
jdx = 0;
mid = malloc(n+1 * sizeof(*mid));
if(mid == NULL)
{
fprintf(stderr, "malloc failed in midstr()\n");
exit(EXIT_FAILURE);
}
for(idx = s; idx < s+n; ++idx)
mid[jdx++] = str[idx];
mid[n] = '\0';

return mid;
}
(Disclaimer: this could undoubtedly be made more efficient by a more
clever programmer than myself.)

Numeric strings can be converted to a number with any of several Std C
library functions. You need to do some reading about how C handles
strings. It's very different than in VB. C doesn't have a "string" type.
Essentially, strings in C are arrays of characters, terminated with a
NULL character.

C's for loops look like this (a simple example; it can get more
complicated):

for(i=0; i<20; i++)
{
/* code here */
}

This is equivalent to VB:

for i = 0 to 19
'code here
next i

where a step value of 1 is implicit.

-JS

Richard Bos

unread,
Nov 9, 2004, 8:54:54 AM11/9/04
to
John Smith <JSm...@mail.net> wrote:

> Essentially, strings in C are arrays of characters, terminated with a
> NULL character.

_Null_ character, please. Case is important. NULL is a macro expanding
to a null pointer constant, not a character. (void *)0 is hardly a good
string terminator, let alone '(void *)0'.

Richard

pete

unread,
Nov 9, 2004, 9:27:57 AM11/9/04
to
Richard Bos wrote:
>
> John Smith <JSm...@mail.net> wrote:
>
> > Essentially, strings in C are arrays of characters,
> > terminated with a
> > NULL character.
>
> _Null_ character, please. Case is important.

or "null character",
since it's not at the begining of a sentence.

> NULL is a macro expanding
> to a null pointer constant, not a character.

... and a null pointer is a pointer
that compares equal to a null pointer constant.

--
pete

Sebastian Kaliszewski

unread,
Nov 9, 2004, 9:48:58 AM11/9/04
to
Richard Bos wrote:

Well, according to standard NULL should expand to 0. (void*)0 is not
conformant IMHO (some pre C89 compilers did so)

rgds
Sebastian

Richard Bos

unread,
Nov 9, 2004, 10:22:27 AM11/9/04
to
Sebastian Kaliszewski <s...@bez.spamu.z.pl> wrote:

Ahem. Neither your humble nor my arrogant opinion are worth what the cat
dragged in; it is the Standard which defines C, not our opinion. And the
Standard says:

7.17#3:
# 3 The macros are
# NULL
# which expands to an implementation-defined null pointer constant;

6.3.2.3#3:
# 3 An integer constant expression with the value 0, or such an
# expression cast to type void *, is called a null pointer constant.

0 is an integer constant expression with the valud 0; (void *)0 is such
an expression cast to type void *; it is, therefore, a null pointer
constant; and because of that, it is a valid expansion of NULL.

> (some pre C89 compilers did so)

There was no such thing as void, pre-C89. IIRC the Standard Committee
nicked it from C++.

Richard

pete

unread,
Nov 9, 2004, 10:28:44 AM11/9/04
to
Sebastian Kaliszewski wrote:

> Well, according to standard NULL should expand to 0. (void*)0 is not
> conformant IMHO (some pre C89 compilers did so)

What standard would that be?

N869
7.17 Common definitions <stddef.h>
[#3] The macros are
NULL


which expands to an implementation-defined null pointer
constant;

6.3.2.3 Pointers
[#3] An integer constant expression with the value 0, or
such an expression cast to type void *, is called a null
pointer constant.

C89 last public draft
4.1.5 Common definitions <stddef.h>
The macros are
NULL


which expands to an implementation-defined null pointer constant;

3.2.2.3 Pointers
An integral constant expression with the value 0, or such an
expression cast to type void * , is called a null pointer constant.

--
pete

dandelion

unread,
Nov 9, 2004, 10:36:03 AM11/9/04
to

"Richard Bos" <r...@hoekstra-uitgeverij.nl> wrote in message
news:4190df39....@news.individual.net...

> There was no such thing as void, pre-C89. IIRC the Standard Committee
> nicked it from C++.

You don't.

It was defined in the first ANSI-C (as opposed to old-style K&R) I used.
That was in '89. C++ was nowhere in sight. Yet.

See
http://www.ericgiguere.com/articles/ansi-c-summary.html

So much for Mr Professional... Don't you wish you had studied at the RUG?


pete

unread,
Nov 9, 2004, 10:49:17 AM11/9/04
to
dandelion wrote:

> That was in '89. C++ was nowhere in sight. Yet.

I'm seeing C++ from 1983.

http://www.google.com/search?hl=en&ie=ISO-8859-1&q=%22c%2B%2B%22+history


--
pete

Chris Torek

unread,
Nov 9, 2004, 11:53:33 AM11/9/04
to
>"Richard Bos" <r...@hoekstra-uitgeverij.nl> wrote in message
>news:4190df39....@news.individual.net...
>> There was no such thing as void, pre-C89. IIRC the Standard Committee
>> nicked it from C++.

No, the "void" type itself (but not "void *") appeared some time
around 1979 or so, about the same time as PWB-Unix and Steve
Johnson's Portable C Compiler. ("void" and "enum" appeared about
the same time. PCC also introduced separated struct/enum namespaces
-- you could now write:

struct A { int a; int b; };
struct B { int b; int a; };

which in Dennis Ritchie's older compilers was invalid; all "struct"
members were in a single namespace, so each had to have a unique
name. This is at least part of the reason that Unix-y "struct"s
use per-struct member prefixes, e.g., "tm_year" inside a "struct
tm", or "st_dev" inside a "struct stat" -- not just "year" and
"dev". PCC had a backwards-compatiblility hack: if X was any
lvalue, or P was a pointer with structure type S, and you wrote
X.field or P->field, and "field" was not a member of the structure
S, PCC would search all the other "struct" and "union" types for
the first one with a member named "field", use that field's type
and offset, and emit a warning. Among other things, this meant
you could write:

struct { char lo, hi; };
short s;
...
s = some_expression();
printf("as word: %o; as bytes: %o, %o\n", s, s.lo, s.hi);

and the old "adb" program used this very construct. Yes, it
sign-extended the bytes, which I found quite annoying. Of course,
Dennis' original compilers did not have "unsigned char" either --
PCC added unsigned variants of all the integral types. Indeed,
early C had no "unsigned" keyword at all; if you wanted unsigned
integers, you declared pointers!)

The "void *" type was an ANSI-committee invention, though.

In article <news:4190e3e5$0$9264$e4fe...@dreader10.news.xs4all.nl>


dandelion <dand...@meadow.net> wrote:
>It was defined in the first ANSI-C (as opposed to old-style K&R) I used.
>That was in '89. C++ was nowhere in sight. Yet.

This is not quite right either. The original ANSI C standard came
out in December 1989, yes, but Stroustrup's C++ book was out well
before that -- I believe I read it in 1986, and apparently it was
published in 1985. Of course, that particular C++ was a very
different language from today's C++.
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.

Dan Pop

unread,
Nov 9, 2004, 2:36:23 PM11/9/04
to
In <cmqsm...@news4.newsguy.com> Chris Torek <nos...@torek.net> writes:

>>"Richard Bos" <r...@hoekstra-uitgeverij.nl> wrote in message
>>news:4190df39....@news.individual.net...
>>> There was no such thing as void, pre-C89. IIRC the Standard Committee
>>> nicked it from C++.
>
>No, the "void" type itself (but not "void *") appeared some time
>around 1979 or so, about the same time as PWB-Unix and Steve
>Johnson's Portable C Compiler. ("void" and "enum" appeared about
>the same time.

"enum" predates "void". It was introduced with the V7 compiler, together
with better support for structures (structures as function parameters and
as function return types, as well as simple assignment operands), slightly
after K&R1 went to print.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Dan...@ifh.de
Currently looking for a job in the European Union

ozbear

unread,
Nov 9, 2004, 3:59:50 PM11/9/04
to

That is one valid expansion. It is also allowed to expand to an
unadorned 0 which will give the correct result, but for the
wrong reason (i.e., luck) when depended upon.

Oz
--
A: Because it fouls the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

Frank Adam

unread,
Nov 9, 2004, 5:48:52 PM11/9/04
to

How about a Null (pointer) and a Nul (character) ? :)

Jaysus, i remember you guys bickering on this many moons ago when i
frequented the C echos.... and you are still fighting over it ?

Just settle on 'zero' already. ;-)

--

Regards, Frank

0 new messages