Performance, for(int i...) vs for(i...)
David Brown
david.brown@hesbynett.no
Mon Aug 27 00:05:00 GMT 2012
On 26/08/12 22:30, Georg-Johann Lay wrote:
> David Brown schrieb:
>> On 26/08/12 20:41, Tim Prince wrote:
>>> On 8/26/2012 1:56 PM, Georg-Johann Lay wrote:
>>>> Tim Prince schrieb:
>>>>> On 08/26/2012 11:30 AM, lab@kayohamid.net wrote:
>>>>>> Hello, I like performance, and until last month i follow what I see
>>>>>> on the web to do better coding for performance, like:
>>>>>>
>>>>>> - Avoid i++, use ++i and so on.
>>>>>>
>>>>>> But now i'm using the assembly (-S) code generated to see if
>>>>>> somethings is correct, and today i'm investigating this:
>>>>>>
>>>>>> int i;
>>>>>> for(i = 0;....);
>>>>>>
>>>>>> vs
>>>>>>
>>>>>> for(int i = 0;...);
>>>>>
>>>>> [...] It's probably important to continue to handle the declaration
>>>>> outside the scope well, as that version is required for C source code
>>>>> by Microsoft compilers, even VS2012.
>>>>> I have had occasion to wish that people didn't rely on non-standard
>>>>> maybe Microsoft is right in forbidding both incorrect and correct C++
>>>>> usage in C code.
>>>>
>>>> It's all vanilla C99, no C++ is needed for that.
>>>>
>>>> Just activate that language standard in your C compiler ;-)
>>>>
>>>> Johann
>>>>
>>> Nothing wrong with maintaining compatibility with a widely marketed
>>> compiler, even if gcc does the job better.
>>
>> Are you suggesting that people who use gcc should limit themselves and
>> the quality of the code they write because some other manufacturer
>> makes a half-hearted C compiler that they hope no one will ever use?
>> MS supports C++ (with their own additions), C# and VB (their own
>> proprietary languages) - they haven't supported C properly for
>> something like a decade.
>>
>> If you want to use MS tools, that's fine - but use the tools they
>> actually recommend you use. And if you want to write C, use a real C
>> compiler.
>>
>> There are many features of C99 that are good additions to making C a
>> better language, and you should use them when writing C code.
>
> Oh, embarrassing. I never used that "widely marketed compiler" and just
> thought that support for a common C standard that is 13 years old now
> is a matter of course...
>
I have almost never used that "widely marketed compiler" myself either -
one of the reasons is that its C support bitrotted years ago. The main
reason I don't use it is because I don't write much C on Windows (I use
mostly Python there), and if I do need C I use gcc.
But I see the same thing in the embedded world. Sometimes I have to use
inferior compilers with more limited features - but if I get to use gcc
for a particular project, then I take advantage of the features it provides.
More information about the Gcc-help
mailing list