14 Replies - 889 Views - Last Post: 08 May 2019 - 08:27 PM Rate Topic: -----

#1 Neonz27   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 08-May 16

Internal Compiler Error 40

Posted 23 April 2019 - 01:18 AM

First off I'd like to apologize for posting my problems here a lot and to thank everyone on this site for being such wonderful mentors to me. I have learned so much from you guys, and everytime I ask for help on a project of mine I feel bad for distracting someone so please don't waste too much of your time on this. I recently encountered a compiler error I have absolutely never in my life seen before. The part of code that I received the error from is below, along with the error.

Compilation Output
Block.cpp: In method `class Transaction Block::getBlockTransaction()':
Block.cpp:27: warning: invalid use of type decl `class Transaction' as expression
Block.cpp:27: Internal compiler error 40.
Block.cpp:27: Please submit a full bug report to `[email protected]'.



Block Source File
#include "Block.hpp"
#include "../include/SHA512/src/sha512.h"
#include <string>
#include <ctime>

// Class Constructor
Block::Block(Transaction _transaction, unsigned int _blockNumber, std::string _previousHash) {
  this->transaction = &_transaction;
  this->blockNumber = _blockNumber;
  this->previousHash = _previousHash;
  this->timestamp = time(NULL);

  this->generateHash();
}

// Class Destructor
Block::~Block() {
  // Freeing member pointer's memory.
  delete this->transaction;

  // Pointing dangling pointer to null value.
  this->transaction = NULL;
}

// Accessor Methods
Transaction Block::getBlockTransaction() {
  return this->Transaction;
}

unsigned int Block::getBlockNumber() {
  return this->blockNumber;
}

std::string Block::getHash() {
  return this->hash;
}

std::string Block::getPreviousHash() {
  return this->previousHash;
}

// Hash Generation Method
void Block::generateHash() {
  // Assigning a temporary pointer to the value of the current time.
  char *_timestamp = ctime(&this->timestamp);

  // Adding the transaction data, block number, previous hash, and timestamp to a string.
  std::string hashContents = std::to_string(this->transaction.getAmount()) + this->transaction.getTransactionType() + this->transaction.getSender() + this->transaction.getReceiver()
+ std::to_string(this->blockNumber) + this->previousHash + std::string(_timestamp);

  // Setting this classes hash value to the hashContents after being hashed with the SHA-1 algorith (made by the NSA in around 2001).
  this->hash = sha512(hashContents);

  // Deletes the temporary timestamp pointer and points it to NULL.
  delete _timestamp;
  _timestamp = NULL;
}



Is This A Good Question/Topic? 0
  • +

Replies To: Internal Compiler Error 40

#2 andrewsw   User is offline

  • quantum multiprover
  • member icon

Reputation: 6792
  • View blog
  • Posts: 28,051
  • Joined: 12-December 12

Re: Internal Compiler Error 40

Posted 23 April 2019 - 01:48 AM

Should it be transaction rather than Transaction?
Was This Post Helpful? 0
  • +
  • -

#3 sepp2k   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2739
  • View blog
  • Posts: 4,383
  • Joined: 21-June 11

Re: Internal Compiler Error 40

Posted 23 April 2019 - 04:47 AM

View PostNeonz27, on 23 April 2019 - 10:18 AM, said:

Block.cpp:27: Internal compiler error 40.
Block.cpp:27: Please submit a full bug report to `[email protected]'.



I assume the reason you didn't do that is that [email protected] hasn't been active since the 90s, correct? So that raises the question: Are you actually using a 20-year old compiler or has that message somehow survived to make it into modern GCC?

If you're not using the current version of GCC, you should upgrade to the current version and see whether this message still pops up. If you are using the current GCC, you should file a bug report on the GCC bug tracker (or maybe two: one about the bug itself and one about the internal error message pointing to a defunct e-mail address).
Was This Post Helpful? 0
  • +
  • -

#4 Neonz27   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 08-May 16

Re: Internal Compiler Error 40

Posted 23 April 2019 - 05:30 AM

I don't quite understand the question. The class was titled Transaction (with a capital T).

View Postandrewsw, on 23 April 2019 - 02:48 AM, said:

Should it be transaction rather than Transaction?


Lmao, no, I can assure you my PC is not 2 decades old. I assume that this genuinely is just a bit of code that survived all these years. Does anyone know how I could go about fixing this issue. Also I'm using the G++ compiler that comes with Cygnus/Cygwin (whatever it's called). The release version is saying egcs-2.91.57. First of all how old is that and second of all where can I get a download?

View Postsepp2k, on 23 April 2019 - 05:47 AM, said:

View PostNeonz27, on 23 April 2019 - 10:18 AM, said:

Block.cpp:27: Internal compiler error 40.
Block.cpp:27: Please submit a full bug report to `[email protected]'.



I assume the reason you didn't do that is that [email protected] hasn't been active since the 90s, correct? So that raises the question: Are you actually using a 20-year old compiler or has that message somehow survived to make it into modern GCC?

If you're not using the current version of GCC, you should upgrade to the current version and see whether this message still pops up. If you are using the current GCC, you should file a bug report on the GCC bug tracker (or maybe two: one about the bug itself and one about the internal error message pointing to a defunct e-mail address).

This post has been edited by Neonz27: 23 April 2019 - 05:34 AM

Was This Post Helpful? 0
  • +
  • -

#5 jimblumberg   User is online

  • member icon

Reputation: 5726
  • View blog
  • Posts: 17,531
  • Joined: 25-December 09

Re: Internal Compiler Error 40

Posted 23 April 2019 - 05:50 AM

Quote

The class was titled Transaction (with a capital T).

That is correct your class name does start with a capital T. However look at this snippet:

Transaction Block::getBlockTransaction() {
	  return this->Transaction;
	}


What exactly are you trying to return? You can't return a Transaction since it's a type not an instance of that type.

By the way you've been told a couple of times that using a single underscore prefix is a bad practice, why are you still using that format? You also don't need the "this->" in front of most of your variable accesses.

Why are you deleting memory that doesn't appear to have been manually allocated?

Lastly for now, your compiler is ancient, you need to get a much newer version.


Jim
Was This Post Helpful? 0
  • +
  • -

#6 sepp2k   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2739
  • View blog
  • Posts: 4,383
  • Joined: 21-June 11

Re: Internal Compiler Error 40

Posted 23 April 2019 - 05:57 AM

View PostNeonz27, on 23 April 2019 - 02:30 PM, said:

I don't quite understand the question. The class was titled Transaction (with a capital T).


Yes, that's the name of the class, but it doesn't really make sense to have the name of a class after this-> - -> should be followed by the name of a member and your member variable is called transaction, not Transaction.

Quote

I can assure you my PC is not 2 decades old


But it looks like the software you installed on it is.

Quote

Also I'm using the G++ compiler that comes with Cygnus/Cygwin (whatever it's called).


The name of the software is Cygwin. Cygnus is the name of the company that originally developed the software. Cygnus was disbanded in the year 2000.

Quote

The release version is saying egcs-2.91.57. First of all how old is that


20 years at least. The last version of EGCS was released in 1999 (I'm not sure whether 2.91.57 was the latest version or whether it's even older than that). The GCC versions currently supported by Cygwin are 7.3, 7.4 and 8.3.

Quote

and second of all where can I get a download?


You can get the current version of cygwin from cygwin.com.
Was This Post Helpful? 1
  • +
  • -

#7 Neonz27   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 08-May 16

Re: Internal Compiler Error 40

Posted 23 April 2019 - 09:12 PM

I'm currently in the process of installing a new compiler that can support C++17 and C18. I continue to use the underscores for visibility to distinguish variables which only belong in this local scope, which is perfectly fine as seen here. Thanks for pointing out the typo with the lowercase transaction variable as well as with the memory allocation. The return this->Transaction statement was my attempt to return a pointer that points to an object belonging to the Block class.

View Postjimblumberg, on 23 April 2019 - 06:50 AM, said:

Quote

The class was titled Transaction (with a capital T).

That is correct your class name does start with a capital T. However look at this snippet:

Transaction Block::getBlockTransaction() {
	  return this->Transaction;
	}


What exactly are you trying to return? You can't return a Transaction since it's a type not an instance of that type.

By the way you've been told a couple of times that using a single underscore prefix is a bad practice, why are you still using that format? You also don't need the "this->" in front of most of your variable accesses.

Why are you deleting memory that doesn't appear to have been manually allocated?

Lastly for now, your compiler is ancient, you need to get a much newer version.


Jim

This post has been edited by Neonz27: 23 April 2019 - 09:16 PM

Was This Post Helpful? 0
  • +
  • -

#8 jimblumberg   User is online

  • member icon

Reputation: 5726
  • View blog
  • Posts: 17,531
  • Joined: 25-December 09

Re: Internal Compiler Error 40

Posted 23 April 2019 - 09:34 PM

Quote

I continue to use the underscores for visibility to distinguish variables which only belong in this local scope, which is perfectly fine as seen here.

What? Look at this snippet: Block::Block(Transaction _transaction, unsigned int _blockNumber, std::string _previousHash). Those variables are not in a "local" scope they are in a global scope, function parameters are global.

Jim
Was This Post Helpful? 0
  • +
  • -

#9 sepp2k   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2739
  • View blog
  • Posts: 4,383
  • Joined: 21-June 11

Re: Internal Compiler Error 40

Posted 24 April 2019 - 02:48 AM

View Postjimblumberg, on 24 April 2019 - 06:34 AM, said:

function parameters are global.


Can you please explain what you mean by that? Certainly you're not saying that the scope of a function parameter extends beyond the body of that function, right?
Was This Post Helpful? 0
  • +
  • -

#10 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 6881
  • View blog
  • Posts: 23,344
  • Joined: 05-May 12

Re: Internal Compiler Error 40

Posted 24 April 2019 - 07:07 AM

The lifetime and any changes you make to parameter values are local to the function, but they are global in the sense that the caller sees what the parameter types and variable names are. It is this visibility of the variable name in the global scope with leading underscores which can potentially lead you into conflict with the compiler since the variables with leading underscores are reserved for its use.
Was This Post Helpful? 0
  • +
  • -

#11 jimblumberg   User is online

  • member icon

Reputation: 5726
  • View blog
  • Posts: 17,531
  • Joined: 25-December 09

Re: Internal Compiler Error 40

Posted 24 April 2019 - 09:25 AM

My biggest objection to using leading underscores anywhere is that it complicates things because you need to worry about when it is acceptable to use the underscore and when it isn't. IMO, it is much easier to avoid this complication and let the compiler implementer have all uses of a leading underscore. This way you know you're okay.

This is a case in point, are those variable names actually visible to the compiler in the global scope or are they only visible in the context of the function? You have to really delve into the standard to be absolutely sure.

By the way I was probably mistaken about those parameters being visible in the global scope, at least with the Microsoft compiler. See this link for more on scope, and don't forget to follow the embedded links as well.

And from that link:

Quote

Local scope A name declared within a function or lambda, including the parameter names, have local scope. They are often referred to as "locals". They are only visible from their point of declaration to the end of the function or lambda body. Local scope is a kind of block scope, which is discussed later in this article.


By the way I also don't recommend using a trailing underscore either because I find the underscore easy to miss.


Lastly, IMO, if you need to method to distinguish parameters from all the rest of a functions variables it probably means that your functions are too complicated or too large.



Jim
Was This Post Helpful? 1
  • +
  • -

#12 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 6881
  • View blog
  • Posts: 23,344
  • Joined: 05-May 12

Re: Internal Compiler Error 40

Posted 24 April 2019 - 10:34 AM

Alternatively, if you really must distinguish between class variables and parameters, always use the this-> in front of the class variables. Personally I abhor that, and I hate one of the style guides and lint rules that enforce this. I tend to the use the m_ prefix for my class variables when writing C++. I'm still on the fence for naming struct variables.
Was This Post Helpful? 1
  • +
  • -

#13 jimblumberg   User is online

  • member icon

Reputation: 5726
  • View blog
  • Posts: 17,531
  • Joined: 25-December 09

Re: Internal Compiler Error 40

Posted 24 April 2019 - 11:32 AM

I also abhor over use of the this-> pointer but I also don't like any prefix or suffix for class variables. One thing I do, and some may consider this horrible as well, is use camel case for class names (with leading capital) and class variable names (no leading capital) and all lower case names (with underscore separator) for everything else. When talking about parameters I tend to try to use more meaningful names for the parameter and less meaningful names for class member variables. For example:

class Account
{
    public:
        Account(int account_id, const std::string& account_name, double account_balance);
    private:
        int idNumber; 
        std::string account;
        double balance;
 


To me the above helps document the external interface, and yet the internal interface is still meaningful because of the content.


Jim
Was This Post Helpful? 2
  • +
  • -

#14 gaxio   User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 7
  • Joined: 24-April 19

Re: Internal Compiler Error 40

Posted 24 April 2019 - 09:57 PM

Apologies if this was already answered, but why are you using a dodgy Windows port of a 20 year old experimental fork of GCC? The compiler should not be crashing no matter how bad the code is, update your compiler. Depending on your requirements, MingW-W64 is the most up to date GCC port you can get for Windows, but it doesn't include the Linux compatibility layer. Or you could get a modern version of Cygwin, or if you're running Windows 10 you can get the Windows Subsystem for Linux. You have a lot of options to get GCC, there's no reason to use that ancient version.

So for the code, shouldn't getBlockTransaction return transaction, not Transaction? Otherwise, it doesn't make much sense. You can't return Transaction, it's a type and not value. You're also using this-> on everything, which is correct but not idiomatic, to say the least. What is getBlockTransaction supposed to do, and what did you attempt to return?
Was This Post Helpful? 1
  • +
  • -

#15 Neonz27   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 08-May 16

Re: Internal Compiler Error 40

Posted 08 May 2019 - 08:27 PM

Thanks everyone for their input and patience, I have solved the issue by downloading another compiler and fixing some typos.

The question has already been answered by fixing some typing mistakes and installing a new compiler, but to answer your question I was trying to have a class Block that contained a bit of information about it as well as an instance of another class Transaction. The function getBlockTransaction was to return a pointer to the Transaction object stored in the Block class.

View Postgaxio, on 24 April 2019 - 10:57 PM, said:

Apologies if this was already answered, but why are you using a dodgy Windows port of a 20 year old experimental fork of GCC? The compiler should not be crashing no matter how bad the code is, update your compiler. Depending on your requirements, MingW-W64 is the most up to date GCC port you can get for Windows, but it doesn't include the Linux compatibility layer. Or you could get a modern version of Cygwin, or if you're running Windows 10 you can get the Windows Subsystem for Linux. You have a lot of options to get GCC, there's no reason to use that ancient version.

So for the code, shouldn't getBlockTransaction return transaction, not Transaction? Otherwise, it doesn't make much sense. You can't return Transaction, it's a type and not value. You're also using this-> on everything, which is correct but not idiomatic, to say the least. What is getBlockTransaction supposed to do, and what did you attempt to return?


Hmm, I guess it really just is personal preference. I will try to change things around to make it more readable for you guys if that would be better. Also what is it about the overuse of this->? What is wrong about it? Should I use ScopeName:: format instead?

View Postjimblumberg, on 24 April 2019 - 12:32 PM, said:

I also abhor over use of the this-> pointer but I also don't like any prefix or suffix for class variables. One thing I do, and some may consider this horrible as well, is use camel case for class names (with leading capital) and class variable names (no leading capital) and all lower case names (with underscore separator) for everything else. When talking about parameters I tend to try to use more meaningful names for the parameter and less meaningful names for class member variables. To me the above helps document the external interface, and yet the internal interface is still meaningful because of the content.


Jim

This post has been edited by Neonz27: 08 May 2019 - 08:27 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1