HP aC++/C Compiler Incompatibility?

This is a discussion on HP aC++/C Compiler Incompatibility? within the C Programming forums, part of the General Programming Boards category; What was the machine that it was originally compiled on? Was it a 32bit processor? If so, it may be ...

  1. #16
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,702
    What was the machine that it was originally compiled on? Was it a 32bit processor? If so, it may be a 32bit --> 64bit issue.

    gg

  2. #17
    Registered User
    Join Date
    Jul 2008
    Location
    Middletown, PA
    Posts
    9

    Got It! Thank you!

    Hey all,

    Solved the problem! Thank you all for your insights!

    I discovered the heart of the problem yesterday afternoon when I started to realize that the problem was in a calculation that converted a price between different monetary units, like Euros to Dollars or Yen to Euros...stuff like that.

    This particular part of the program is calculating what it costs for one plant to sell parts to another plant - which may be in a different country - and the way the program works is by using two factors - a conversion TO USD factor, and a conversion FROM USD factor, because, for some legal reason, all the conversions have to go through US dollars. So it's fairly easy, the calculation looks like this ((Price * To USD factor) * From USD factor). If a currency is only being converted to USD, though, it just sets the 'From USD' factor to 1, so it makes no difference.

    I did a printf statement on the 'From USD' factor and found out it was being set at 10! Not 1. I traced the problem back further to where that factor (it's actualy like 1.0000000000000) is loaded into an array - one character per index. The array is of size 17, but only indexes 0-15 were being read in and used! I think what is happenning is that the old compiler set aside memory for arrays when they were declared - but the new compiler actually zeros out the indicies. When I printed the contents of the array, there was an extra zero attached to what was read in...thus giving us our order of magnitude difference in the conversion factor, giving us an order of magnitude difference in the converted price, and skewing the results in our final output.

    Shrunk the array down to the proper size for the input - problem solved. It must have been working by luck before.

    None of you would happen to know of a compiler option for the HP aC++/C Compiler version A.05.50 that would tell it NOT to zero out arrays, would you?

  3. #18
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,031
    I doubt it zeros out arrays. I have yet to see a compiler that does that.
    Regardless of it it does or not, arrays which are not initialized contains undefined data, which is why you should always initialize it before use.
    But if there are elements that aren't used as you say, then they shouldn't be there in the first place.

    I believe you're going to have to provide more information. Perhaps a snippet of the code where you found the error?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #19
    Registered User
    Join Date
    Jul 2008
    Location
    Middletown, PA
    Posts
    9

    Zeroing Out Arrays

    Of course the arrays were initialized before use. You can't use the space in them unless you do. You can't just say array[4]=7 without defining the array first, which includes initializing it. And trust me, I know what I'm talking about - it zeroes out the array. There's no other possible way an extra zero could have gotten in there. I've watched the index thoroughly throughout the program's run, and the array definitely has one more zero in it than the input file does.

  5. #20
    Registered User
    Join Date
    Jul 2008
    Location
    Middletown, PA
    Posts
    9

    Code

    I'm not going to provide code, you may consider this thread closed. The problem has been solved. Thanks.

  6. #21
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    Quote Originally Posted by ShearWater509 View Post
    Of course the arrays were initialized before use. You can't use the space in them unless you do. You can't just say array[4]=7 without defining the array first, which includes initializing it. And trust me, I know what I'm talking about - it zeroes out the array.
    Um, excuse me?

    Code:
    #include <stdio.h>
    
    int main(void)
    {
    	int i;
    	int array[10];
    	
    	array[4] = 7;
    	
    	for(i=0;i<sizeof(array)/sizeof(*array);i++)
    	{
    		printf("array[%d] = %d\n", i, array[i]);
    	}
    	
    	return 0;
    }
    Output on a Windows XP system compiled with MinGW:

    Code:
    array[0] = 2009288233
    array[1] = 10
    array[2] = 0
    array[3] = 0
    array[4] = 7
    array[5] = 2293556
    array[6] = -1
    array[7] = 2293728
    array[8] = 2009291924
    array[9] = 2009147472
    Arrays are not initialized by default, most certainly not to 0. If this is what you are speaking about, you are relying on undefined behavior, which we told you about previously.

    Initialize your arrays manually. Of special interest, if you set the array to any value upon declaration, it will automatically initialize the other remaining elements of the array to 0. If this is what you are speaking about, then this is part of the language and you should not be able to find a compiler extension to break proper C behavior in this regard. Initialize your arrays properly.

  7. #22
    Registered User
    Join Date
    Jul 2008
    Location
    Middletown, PA
    Posts
    9

    Arrays

    The arrays ARE initialized exactly as you show.

    Listen, there's no way for me to prove this to you unless you come here and look at the code, which, frankly, is illegal because it is proprietary software. I was just looking for hints, but ended up not needing them.

    The problem is solved, this will be my final post on the matter.

  8. #23
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    If the array is local, it's "initialized" to random stuff by default as shown above. If the array is global, then all the array elements are initialized to zero by default. That's specified in the language and I doubt there's a compiler flag that will override it.

  9. #24
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    Quote Originally Posted by ShearWater509 View Post
    The arrays ARE initialized exactly as you show.
    Um, you said they were initialized to 0, and I proved that they are not. What are you even trying to argue? You're obviously wrong, unless, as tabstop points out, you're using global or local static data. Even that doesn't make much sense for your situation since your other compiler would have initialized all of the memory in question to 0 as well.

    What is likely is that the first compiler initialized all of the local arrays to 0 as a feature, and whoever was used to that compiler when they wrote code for it got lazy and didn't actually initialize everything properly. Thus, the code is relying on undefined behavior, which resulted in you guys not being able to figure it out for months.

    This is a good practical example for why people should write standard code.

  10. #25
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    Quote Originally Posted by ShearWater509 View Post
    unless you come here and look at the code, which, frankly, is illegal because it is proprietary software.
    It's not illegal to look at proprietary software. Copying is illegal under copyright law, you showing it to me might make you break your non-disclosure agreement, but if I were to walk by your desk and read the code on your screen, neither of us is breaking any laws.

    QuantumPete
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

  11. #26
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by QuantumPete View Post
    It's not illegal to look at proprietary software. Copying is illegal under copyright law, you showing it to me might make you break your non-disclosure agreement, but if I were to walk by your desk and read the code on your screen, neither of us is breaking any laws.

    QuantumPete
    You may not be breaking laws, but you may be breaking the non-disclosure agreement, and whilst that may not end up with you or me in prison, the potential damages in a lawsuit to a small or medium size company could be bad indeed.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem building Quake source
    By Silvercord in forum Game Programming
    Replies: 16
    Last Post: 07-11-2010, 10:13 AM
  2. C Compiler and stuff
    By pal1ndr0me in forum C Programming
    Replies: 10
    Last Post: 07-21-2006, 12:07 PM
  3. hp iPAQ 6300 && C compiler || C# compiler
    By xddxogm3 in forum Tech Board
    Replies: 2
    Last Post: 12-07-2004, 07:28 AM
  4. OpenScript2.0 Compiler
    By jverkoey in forum C++ Programming
    Replies: 3
    Last Post: 10-30-2003, 01:52 PM
  5. Compiler Design... Anyone That Can Help!
    By ComputerNerd888 in forum C++ Programming
    Replies: 3
    Last Post: 09-27-2003, 10:48 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21