473,799 Members | 3,270 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Large string constant causes C# compiler crash

I created a C# application with some large string constants and whenever I
try to build the solution the compiler crashes with no error message. On
further analysis the problem seems to occur when the string constant has
around 2100 character. I tried changing the constant declaration to a string
variable declaration and it works fine.

Any ideas?

The following code can be used to reproduce the error:

const string TEST =
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890" +
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890" +
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890" +
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890" +
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890" +
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890" +
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890" +
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890" +
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890" +
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890" +
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890" +
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890" +
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890" +
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890" +
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890" +
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890" +
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890" +
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890" +
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890" +
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890" +
"12345678901234 567890123456789 012345678901234 567890123456789 012345678901234 567890123456789 01234567890";

Regards
Gnik
Nov 16 '05
11 3097
Excellent Daniel, always good to know.

I'm guessing that using constants the way gnik wanted to is probably quite a
rare scenario anyway, because the only reason you would want to put it's
declaration inside a class member is if it is unlikely to be called
(therefore having a slight potential benefit over declaring as a private
class const).

Thanks for your input too.

Br,

Mark.

"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in
message news:OP******** ******@TK2MSFTN GP15.phx.gbl...

"Mark Broadbent" <no****@nospam. com> wrote in message
news:%2******** *******@TK2MSFT NGP11.phx.gbl.. .
Having spent a bit of time with this there are several clear things.
1. Compiles ok when const is a class member.
2. Falls over when large string const is within Class member (have tried
methods and properties -static or not does not make a difference)
3. Length of const IS making a difference as to whether falls over or
not.
4. Your statement IS VALID.

This seems to be a bug in visual studio since your project will compile
with the command line util csc.


On the plus side, it appears that its fixed in whidbey, atleast for up to
three times the length of the repo case.

Nov 16 '05 #11
Thanks for the suggestions, it's a relief to know it's not a problem with my
setup. I'll recode to put the constants at class level as in this case it
makes no difference in this particular application.

I was actually using the constants for SQL statements, bad practice I know,
but I had some issues with passing parameters to Access stored queries. I
need to go back a revisit that, but I'll save it for another thread when I
have more time.

Thanks again.

Gnik

"Mark Broadbent" wrote:
Excellent Daniel, always good to know.

I'm guessing that using constants the way gnik wanted to is probably quite a
rare scenario anyway, because the only reason you would want to put it's
declaration inside a class member is if it is unlikely to be called
(therefore having a slight potential benefit over declaring as a private
class const).

Thanks for your input too.

Br,

Mark.


Nov 16 '05 #12

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

Similar topics

20
2109
by: CoolPint | last post by:
While I was reading about const_cast, I got curious and wanted to know if I could modify a constant variable through a pointer which has been "const_cast"ed. Since the pointer would be pointing to the constant variable and if I changed the value through the pointer, the constant variable should have been modified. Well, that's what I thought until I wrote the following and run it. #include <iostream> using std::cout; using std::endl;
18
2433
by: JKop | last post by:
Can some-one please point me to a nice site that gives an exhaustive list of all the memberfunctions, membervariables, operators, etc. of the std::string class, along with an informative description of how each works. I've been trying Google for the last 20 minutes but can't get anything decent. Thanks.
15
3340
by: Ramaraj M Bijur | last post by:
Hi All, Could anyone help me to resolve following problem in C the IDE used is Microsoft VC++, Please let me know the which option in VC++ will do the needful The problem statement: overwrite of charcter in constatnt string like char *str="Hi all"; str='A'; the result of this str points to the string "Hi All"
19
3472
by: Hal Styli | last post by:
Hello, Can someone please help. I need to use a large array and I'm not sure when one should use (A) and when one should use (B) below:- #define MAX 10000000 (A) int x;
3
5268
by: Mark Rockman | last post by:
------ Build started: Project: USDAver2, Configuration: Debug .NET ------ Preparing resources... Updating references... Performing main compilation... error CS0583: Internal Compiler Error (0xc0000005 at address 535F072A): likely culprit is 'BIND'. An internal error has occurred in the compiler. To work around this problem, try simplifying or changing the program near the locations listed below. Locations at the top of the list are...
10
11329
by: william | last post by:
#include <stdio.h> int main() { char *str=NULL; char x="today is good!"; printf("%s", str); str=strtok(x," "); if (str=="today") //<==here is line that confuses me printf("they equals!\n");
10
512
by: baje | last post by:
//new to c++ //have a pointer char *name; //want to enter a name *name = "dave"; //initialize cout<<"enter a name" cin>>name; cout<<" name entered is"<<name; //get a compiler error
21
55637
by: phpCodeHead | last post by:
Code which should allow my constructor to accept arguments: <?php class Person { function __construct($name) { $this->name = $name; } function getName()
17
9959
by: byte8bits | last post by:
How does C++ safely open and read very large files? For example, say I have 1GB of physical memory and I open a 4GB file and attempt to read it like so: #include <iostream> #include <fstream> #include <string> using namespace std; int main () {
0
10490
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10238
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10030
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7570
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6809
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5467
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5589
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4145
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2941
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.