473,499 Members | 1,610 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Convert VB code to C code.

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
Nov 14 '05 #1
23 2471
Hmm. Interesting, yet oddly not inappropriate, crosspost list on
this one.

In article <ce**************************@posting.google.com >,
Kenneth Osenbroch <ke***************@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 dj******@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
Nov 14 '05 #2
Kenneth Osenbroch wrote:

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.


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 (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Nov 14 '05 #3

"Kenneth Osenbroch" <ke***************@telenor.com> wrote in message
news:ce**************************@posting.google.c om...
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]);

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).

Nov 14 '05 #4

"cr88192" <cr*****@remove.hotmail.com> wrote in message
news:a3***************@news.flashnewsgroups.com...

"Kenneth Osenbroch" <ke***************@telenor.com> wrote in message
news:ce**************************@posting.google.c om...
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));

Nov 14 '05 #5
On 2 Nov 2004 13:01:06 -0800, ke***************@telenor.com (Kenneth
Osenbroch) 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, and how "Val(Mid.." and "Right(Str..." are
translated into C. Any further help would be greatly appreciated.

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
Nov 14 '05 #6
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
Nov 14 '05 #7
"cr88192" <cr*****@remove.hotmail.com> wrote:
"Kenneth Osenbroch" <ke***************@telenor.com> wrote in message
news:ce**************************@posting.google.c om...
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
Nov 14 '05 #8

"Richard Bos" <rl*@hoekstra-uitgeverij.nl> wrote in message
news:41****************@news.individual.net...
"cr88192" <cr*****@remove.hotmail.com> wrote:
"Kenneth Osenbroch" <ke***************@telenor.com> wrote in message
news:ce**************************@posting.google.c om...
> 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...

Nov 14 '05 #9
"Richard Bos" <rl*@hoekstra-uitgeverij.nl> wrote in message
news:41****************@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
Nov 14 '05 #10
ke***************@telenor.com (Kenneth Osenbroch) wrote in message news:<ce**************************@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?


Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <ctype.h>
  3.  
  4. int main(void)
  5. {
  6. const char* sReference  = "12dgh3456";
  7. const int   iMultiplier = 11;
  8.  
  9. float fReferenceCheckSum;
  10. int   iSum     = 0;
  11. int   iCounter = strlen(sReference);
  12.  
  13. while (--iCounter >= 0)
  14. {
  15. iSum += isdigit(sReference[iCounter]) ?
  16. (sReference[iCounter] - '0') * iMultiplier : 0;
  17. }
  18.  
  19. fReferenceCheckSum = (float) ((10 - (iSum % 10)) % 10);
  20.  
  21. printf("fReferenceCheckSum = %.0f, iSum = %d",
  22. fReferenceCheckSum, iSum);
  23.  
  24. getchar();
  25. return 0;
  26. }
  27.  
---
Note: My reply address is invalid.
Nov 14 '05 #11
rl*@hoekstra-uitgeverij.nl (Richard Bos) wrote in message news:<41****************@news.individual.net>...
"cr88192" <cr*****@remove.hotmail.com> wrote:
"Kenneth Osenbroch" <ke***************@telenor.com> wrote in message
news:ce**************************@posting.google.c om...

[ 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
Nov 14 '05 #12
Kenneth Osenbroch 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, and how "Val(Mid.." and "Right(Str..." are
translated into C. Any further help would be greatly appreciated.

Thanks,
Kenneth


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
Nov 14 '05 #13
John Smith <JS****@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
Nov 14 '05 #14
Richard Bos wrote:

John Smith <JS****@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
Nov 14 '05 #15
Richard Bos wrote:
John Smith <JS****@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'.


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

rgds
Sebastian
Nov 14 '05 #16
Sebastian Kaliszewski <sk@bez.spamu.z.pl> wrote:
Richard Bos wrote:
John Smith <JS****@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'.


Well, according to standard NULL should expand to 0. (void*)0 is not
conformant IMHO


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
Nov 14 '05 #17
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
Nov 14 '05 #18

"Richard Bos" <rl*@hoekstra-uitgeverij.nl> wrote in message
news:41****************@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?
Nov 14 '05 #19
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&i...%2B%22+history
--
pete
Nov 14 '05 #20
>"Richard Bos" <rl*@hoekstra-uitgeverij.nl> wrote in message
news:41****************@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:41**********************@dreader10.news.xs4a ll.nl>
dandelion <da*******@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.
Nov 14 '05 #21
In <cm*********@news4.newsguy.com> Chris Torek <no****@torek.net> writes:
"Richard Bos" <rl*@hoekstra-uitgeverij.nl> wrote in message
news:41****************@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: Da*****@ifh.de
Currently looking for a job in the European Union
Nov 14 '05 #22
On Tue, 09 Nov 2004 13:54:54 GMT, rl*@hoekstra-uitgeverij.nl (Richard
Bos) wrote:
John Smith <JS****@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


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?
Nov 14 '05 #23
On Tue, 09 Nov 2004 14:27:57 GMT, pete <pf*****@mindspring.com> wrote:
Richard Bos wrote:

John Smith <JS****@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 ofasentence.
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.

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
Nov 14 '05 #24

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

Similar topics

4
3598
by: Eric Lilja | last post by:
Hello, I've made a templated class Option (a child of the abstract base class OptionBase) that stores an option name (in the form someoption=) and the value belonging to that option. The value is...
4
9700
by: aevans1108 | last post by:
expanding this message to microsoft.public.dotnet.xml Greetings Please direct me to the right group if this is an inappropriate place to post this question. Thanks. I want to format a...
6
10127
by: Ricardo Quintanilla | last post by:
i have a code that sends data to a socket listening over as400 platform, the socket responds to me as a "byte array". then i need to convert the "byte array" into a string. the problem is that...
5
18686
by: simon | last post by:
I have datetime variable: Datetime tsEndTime; Should I use (DateTime): tsEndTime=(DateTime)rdr.GetValue(15) or is better to use: tsEndTime=Convert.ToDateTime(rdr.GetValue(15))
3
2679
by: Thubaiti | last post by:
Hi, I have this code in my ASP.NET and I want to convert it to C# (code behind) <asp:Repeater id="subCategoryRepeater" runat="server"> <ItemTemplate> <ul> <li> <asp:HyperLink...
25
7220
by: Charles Law | last post by:
I thought this was going to be straight forward, given the wealth of conversion functions in .NET, but it is proving more convoluted than imagined. Given the following <code> Dim ba(1) As...
7
29151
by: patang | last post by:
I want to convert amount to words. Is there any funciton available? Example: $230.30 Two Hundred Thirty Dollars and 30/100
6
1407
by: patang | last post by:
Could someone please tell me where am I supposed to put this code. Actually my project has two forms. I created a new module and have put the following code sent by someone. All the function...
3
8718
by: mrajanikrishna | last post by:
Hi Friends, I am accepting a number from the user entered in a textbox. I want to assign to a variable in my code and assignt this to that variable. double num1 = (double)txtNum1.text; ...
0
10705
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
0
7132
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,...
0
7009
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...
0
7223
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...
0
5475
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,...
1
4919
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...
0
4602
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...
0
3103
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...
0
3094
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
302
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...

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.