• C


int average(char *first, char *second, long ii, double mm, ...)
   int count = 0, sum = 0, i;
   char *buffer;
   va_list marker;
   va_start(marker, mm);
   while (strcmp(buffer = va_arg(marker, char *), NULL))
      printf("[%s]\n", buffer);
   va_end(marker); /* Reset variable arguments. */
   return (sum ? (sum / count) : 0);

void main()
   printf("average=%d\n", average("avg", "DDD", 123L, 23.0, "10", "20", "39", NULL));
In turbo C/C++,the program could execute completely.
In VC 6.0,aftering executing,the program will show  access exception  error.
I find the program 's problem is on:
==> while (strcmp(buffer = va_arg(marker, char *), NULL))
But i don't know why???
Why 's difference between in real mode and in protect mode???
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Sjef BosmanGroupware ConsultantCommented:
NULL is NOT a string, but zero! If you want to compare a string to an empty string, use "". If you want to verify that a pointer is non-zero (i.e. points to a valid location (?)), then don't use strcmp, but use ptr!=NULL
TKDAuthor Commented:
I know what you say.
But i would like to know why the program exist a access exception in VC 6.0.
I execute the progrma in turbo C/C++,and there isn't any exception.
Sjef BosmanGroupware ConsultantCommented:
You might just be lucky to get it running at all! The program is just plain wrong.

Most likely explanation: the address 0 will be readable using one runtime system and illegal using the other. Depends on the code that is generated. Suggestion: compare the generated assembly code in both cases.
Cloud as a Security Delivery Platform for MSSPs

Every Managed Security Service Provider (MSSP) needs a platform to deliver effective and efficient security-as-a-service to their customers. Scale, elasticity and profitability are a few of the many features that a Cloud platform offers. View our on-demand webinar to learn more!

TKDAuthor Commented:
Isn't there any different between access address 0 in real mode and in protect mode?
I find that there isn't any exception in real mode.
Sjef BosmanGroupware ConsultantCommented:
Could be, I don't know. Some parts of the program's data memory could be in a protected (R/O) segment. I also know of environments where the lower memory block was excluded (addresse 0-255 or even more), to generate just the error you are getting.
well, in C language all strings are arrays represented by their first bytes, and when you call strcmp("str1", "str2") you are actually passing pointers to strings "str1" and "str2" these strings have a null character at their ends to distinguish the end of string hence the name NULL TERMINATED STRING.

you can pass NULL as an argument to all string related routines, it is legal in compilers perspective, you are just passing an addres, albeit it is zero.

data at address zero (read this as NULL) is inaccessible on windows platform, so you got an exception, whereas DOS programs have no such limitation.

As far as I remember memory location zero has a string like "Turbo C/C++ ...." by default on programs compiled with Borland C products. so if you pass NULL as an argument to a string function you are practically passing this Borland copyright note string to your function.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TKDAuthor Commented:
Windows platform don't  permit to access data at address zero.
Dos programs don't have such limitation.
Where could I get  those information???
The difference is probably in the implementation of the standard
library routines between Turbo-C and VC++.  The Borland library
might check for NULL parameters and exit gracefully, whereas the
Microsoft library probably considers it a programming error, and the
seg-fault will draw immediate attention to the problem.

>>Windows platform don't  permit to access data at address zero.
>>Dos programs don't have such limitation.
>Where could I get  those information???

I should say restriction is a better choice of word than limitation, on my previous comment.
You can find these kind of information on platform SDK documentations.
TKDAuthor Commented:
I could find these kind of information on platform SDK documents.
But I don't know how to use keyword to search??? or where to get those information???
Could someone hint me???
if you want to go deep into windows system programming aspects

you can take a look at win32 programming FAQ at

or buy a book on win32 system programming
TKDAuthor Commented:
Thanks for alikoank,but I think there isn't any thing about the topic.
I want to know what 's different between access memory in real mode and in protect mode.
I wouldn't like to know how to window programming.
Sjef BosmanGroupware ConsultantCommented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.