473,804 Members | 3,074 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

operator new with "value type"


Hello,

I'm a developer coming from C++ and Java ... I've going thru
"Effective C#" (which highly recommend for people coming from other
languages wanting to learn C#), and it states that "value types" are
always created on the stack, but then showed the "creation" of one w/
operator new. I guess it makes sense, but is it true that:

MyValueType t;

and

MyValueType t = new MyValueType();

are equivalent w/ regard to where the object is stored? That just
seems odd to me. I suppose this is probably in a FAQ somewhere (I
welcome any pointers to any FAQ list that answers this), but I
couldn't find it stated obviously (tho I didn't spend too long
looking :) ...

-Charlie
Dec 7 '07
24 2082
Lew wrote:
Arne Vajhøj wrote:
>Lew wrote:
>>In fact, within FORTRAN itself there were changes within "familiar
constructs" . A loop index variable was scoped to the loop in some
dialects, but wider in others. The newer languages changed the
meaning of the familiar construct of "scope", and made it explicit,
thus fixing a lot of weird bugs.

Fortran 90/95 ?

Not possible in 66 and 77.

(I know that C++ had such a problem before ANSI standardization )

I don't remember which version of FORTRAN scoped loop variables to the
loop for you, but it was in 1980. The reason was optimization - the
loop variable could be enregistered. The register would be colored by a
different variable immediately after loop exit.
Are you sure you remember correct ?

Declarations in Fortran (at least the old versions) are always
before executable statements and therefor with subroutine/function
wide scope. I would assume that implicit declared variable would be
the same.

And AFAIK the Fortran standard explicitly define that the loop
variable to be last value + step after the do loop.

Arne

Dec 27 '07 #21

"Barry Kelly" <ba***********@ gmail.comwrote in message
news:q1******** *************** *********@4ax.c om...
Ben Voigt [C++ MVP] wrote:
>"Jon Skeet [C# MVP]" <sk***@pobox.co mwrote in message
news:MP******* **************@ msnews.microsof t.com...
<"Ignacio Machin \( .NET/ C# MVP \)" <machin TA laceupsolutions .com>>
wrote:
Interesting, it might be the case that I have not seen that much code
that
was not mine :)

It would be overkill to force the use of { though.

Would it really? I certainly find code much more readable that way, and
it *is* required for various constructs IIRC.

do-while and switch require the braces

---8<---
class App
{
static void Main()
{
do System.Console. WriteLine(); while(false);
}
}
--->8---
Ok, you win. I have *never* before seen a do-while without braces in either
C#, C++, or plain C.
>
C# switch does require braces, although consider C/C++:

---8<---
int main(void)
{
switch (0);
return 0;
}
--->8---

(I in no way condone use of the above forms; though I'm ambivalent about
requiring {} on if-statement sub-blocks.)

-- Barry

--
http://barrkel.blogspot.com/

Dec 28 '07 #22
Ben Voigt [C++ MVP] <rb*@nospam.nos pamwrote:

<snip>
Ok, you win. I have *never* before seen a do-while without braces in either
C#, C++, or plain C.
I hope I never see one in production code, either :)

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Dec 28 '07 #23
Ben Voigt [C++ MVP] wrote:
"Barry Kelly" <ba***********@ gmail.comwrote in message
> do System.Console. WriteLine(); while(false);
Ok, you win. I have *never* before seen a do-while without braces in either
C#, C++, or plain C.
Neither have I.

But considering that in Pascal you can even do multiple
statements in a repeat until loop without begin end blocks,
then it should not be that surprising.

Arne
Dec 28 '07 #24
Arne Vajhøj wrote:
Ben Voigt [C++ MVP] wrote:
"Barry Kelly" <ba***********@ gmail.comwrote in message
do System.Console. WriteLine(); while(false);
Ok, you win. I have *never* before seen a do-while without braces in either
C#, C++, or plain C.

Neither have I.

But considering that in Pascal you can even do multiple
statements in a repeat until loop without begin end blocks,
then it should not be that surprising.
It isn't like Pascal - in C/etc., the logic is that a *single* statement
is expected between the 'do' and the 'while', so the parser code looks
very roughly like this (in LL recursive descent):

case DO:
Skip(DO);
body = ParseStatement( );
Expect(WHILE);
// etc...

It could have been rewritten to something like:

case DO:
Skip(DO);
body = ParseBlockState ment();
Expect(WHILE);
// etc...

.... but it never has, for reasons unknown.

-- Barry

--
http://barrkel.blogspot.com/
Dec 30 '07 #25

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

Similar topics

5
17713
by: johnsuth | last post by:
I want to produce a trivial demonstration of dynamic modification. I thought that pressing a button might change its color. I studied O'Reillys books and successfully created the button with a fancy style, but the onclick fails to do anything no matter what permutation of parameters I try. <input type=button style=background-color:yellow;color:blue;font-family:Arial;font-style:italic;font-weight:bold name="xyz" value="CHANGE COLOUR"...
388
21948
by: maniac | last post by:
Hey guys, I'm new here, just a simple question. I'm learning to Program in C, and I was recommended a book called, "Mastering C Pointers", just asking if any of you have read it, and if it's worth the $25USD. I'm just looking for a book on Pointers, because from what I've read it's one of the toughest topics to understand. thanks in advanced.
2
5665
by: IkBenHet | last post by:
Hello, I am uploading a file using this form in ASP.NET. I have also added a simpel textfield: <form runat="server" enctype="multipart/form-data"> <input type="file" id="oFile" Name="oFile" size="70" runat="Server"> <input type="text" SIZE="20" MAXLENGTH="20" id="Name" NAME="Name"> <input type="submit" id="Submit" runat="Server" value="Submit" OnServerClick="SubmitButton_Click"> </form>
10
21174
by: PB | last post by:
Hi ! I have the following code, which I am using in an Embedded systems, c-compiler.. However I see the same problem with GCC too.. I need the last 10 bits of an address pointer, which is completly know at link time, but will be symbols at the compile time. I used the following code for this initalization.. uint32 data_ptr_mask = ((uint32) data) & 0x3ff;
3
2490
by: IR | last post by:
Hi, I've been trying to do the following (which doesn't compile) : template<class T, class F = Example<T struct Example { F foo(); };
21
2425
by: Steven T. Hatton | last post by:
I'm trying to improve my formal understanding of C++. One significant part of that effort involves clarifying my understanding of the vocabulary used to describe the language. This is from the C++ Standard: "" "...sequence of operators and operands that specifies a computation...". That means to me that an expression can be "executed". I am purposely
5
2277
by: Diwa | last post by:
Does the "value" type (value as in key-value pair )of "std::map" require a default ctor even if it is not used ? If I comment out Line 1 in the code attached later, i.e remove the default ctor of "value" type of map, I get the following error: // -------------------------------------------- /usr/include/c++/3.2.3/bits/stl_map.h:225: no matching function for call to `FieldType::FieldType()'
7
2704
by: LoneHunter01 | last post by:
When I try to compile the below files, the complier says: the WordNode h in BST.cpp: "WordNode" does not name a type also in BST.cpp: "WordNode" undeclared, first use of this function So, any advice? Sorry for the huge post, just wanted to make sure you can understand the problem. As it is, I'm lost.... I've included the WordNode header file, so why can't I create/use WordNode objects/methods (in BST)? WordNode.h #ifndef RANDOM...
1
7087
by: mark | last post by:
Forgive me if this seems like a stupid question but I need help... I'm trying to do a simple online form that emails me the results from a few fields. Here is the code: <form action="http://cm1web1/WebSurveyComponents/script/ processform.asp" method="post">
0
9569
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10318
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10302
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
10069
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...
0
9130
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7608
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
6844
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
5503
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...
2
3802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.