OK this question appears many times across many context on the web. However, I am yet to find a sufficient answer. It seems like there is no way of displaying globals in the Debug/Variables view. A workaround this is to use the Expressions view. This is fine for watching the variables, but it won't let you change their contents, as in the Variables view.
Now, one could do so via the Memory view. This is OK when dealing with simple variables, but gets complicated when dealing with compound objects (e.g., structures).
So, how can you easily watch and change the values of globals and static variables in Eclipse CDT?
It seems that changing value of global variables is possible in the Expressions view. From some reason this did not work earlier, which is why I asked this question.
Obviously, it can only work when the expression is an lvalue.
(I am not deleting this question just in case it will be helpful to someone in the future, but if the mods think it should be deleted, that's fine with me)
Related
I often find myself reading other developer's C code containing expressions like
ptr->member1.member2[i].another_member.final_member = 42;
and needing to find out what type final_member is. Usually what I do is to track down the chain of types using C tags, starting at the declaration of ptr and digging my way into the chain of members. This is cumbersome and often I'm stuck somewhere scratching my head, asking myself "What was the next member in the chain?" To make matters worse, a simple grep for final_member in the source tree turns up too many false positives due to the name being reused in more than one struct.
Is there a way to make vim give me the answer directly? I'm willing to install any plugin and even type a few characters while the cursor is on the final_member or select the whole expression :-) Non-GUI solutions preferred.
If i'm working on a project with several nested structs i add preview to the completeopt option.
In combination with the excellent omnicppcomplete plugin a tiny scratch window pops up if you select an entry in the completion menu. That scratch window shows some properties of the selected tag. Among other things it contains the search pattern for the tag which in case of a struct member usually contains its datatype.
I really suggest you to use plugin clang_complete (or some other plugin powered by clang) for completion. It will give you pure completion of C/C++/Objective-C code by real compiler, not ugly method by tags. Each item in completion menu also has type of field (that's what you are looking for)
Omnicppcomplete fails often on complicated expressions. Clang works great, since it is real awesome compiler.
Me and my colleague are developing an ms access based application. We are designing and coding different pages/forms in order to divide work. We plan to merge our work later. How can we do that without any problems like spoiling the design and macros? We are using Ms access 2007 for front end and sqlserver 2005 as the datasource.
I found an idea somewhere on bytes.com. I can import forms, reports, queries,data and tables that I want.I'm going to try this. However, it's just an idea.So, need to study this approach by trial and error techniques.
The most important requirement is to complete the overall design before you start coding. For example:
All the forms must have the same style. Help and error information must be provided in the same way on each form. If a user can divide the forms into two sets, you have failed.
The database design must be finished with a complete, written description of each table, its relationships and its attributes.
The purpose and parameters for each major macro must be defined. If macro A1 exists only to service macro A then A1 is not a major macro and only A's author need know of its details until coding is complete.
Agreed a documentation style and detail level. If the application needs enhancement in six or twelve months' time, you should be able to work on the others macros and forms as easily as on your own.
If one of you thinks a change to the design is required after coding has started, this change must be documented, agreed with the other and the change specification added to the master specification.
Many years ago I lectured on (Electronic Data interchange (EDI). With EDI, the specification is divided into two with one set of organisations providing applications for message senders and another set providing applications for message receivers. I often used an example in my lectures to help my audience understand the importance of a complete, unambiguous specification.
I want two shapes, an E and a reverse-E, which I can fit together to create a 10 cm square. I do not care what they are made of providing they fit together perfectly.
If I give this task to a single organisation, this specification will be enough. One organisation might use cardboard, another metal, but I do not care. But suppose I ask one organisation to create the E and another the reverse-E. How detailed does my specification have to be if I am to get my 10 cm square? I would suggest: material, thickness and dimensions of the E. My audience would compete to suggest more and more obscure characteristics that had to match: density, colour, pattern, texture, etc, etc.
I was not always convinced my audience listened to the rest of my lecture because they were searching for a characteristic that would cap all the others. No matter, I had got across my major point which was why EDI specifications were no mind-blowingly detailed.
Your situation will not be so difficult since you and your colleague are probably in the same room and can talk whenever you want. But I hope this example helps you understand how easy is it for the interface between your two parts to be less than seamless if you do not agree the complete design at the beginning. It's the little assumptions - I though you knew I was doing it that way - that will kill your application.
New section
OK, probably most of my earlier advice was inappropriate in your situation.
So you are trying to modify code you did not write in a language you do not know. Good luck; you will need it.
I think scope is going to be your biggest problem. Most modern languages have namespaces allowing you to give a variable or a routine as much or as little scope as you require. VBA only has three levels.
A variable declared within a function or subroutine is automatically private to that function or subroutine.
A variable declared as Private within a module is invisible to functions and subroutines in other modules but is visible to any function or subroutine within the module.
A variable declared as Public within a module is visible to any function or subroutine within the project.
Anything declared within a form is private to that form. If a form wishes to pass a value to an outside function or subroutine, it can do so by writing to a public variable or by passing it in a parameter to a public function or subroutine.
Avoiding Naming Conflicts within VBA Help gives useful advice.
Form and module names will have to be unique across the merged project. You will not be able to avoid have constants, variables, functions and sub-routines which are visible to the other's functions and sub-routines. Avoiding Naming Conflicts offers one approach. An approach I have used successfully is to divide the application into sub-applications and, if necessary, sub-sub-applications and to assign a prefix to each. If every public constant, variable, function and sub-routine name has the appropriate prefix you can simulate namespace type control.
I'm creating a small Avida-style life simulation. I started out with a very basic, everything-is-global 600-line program in a single file to test some ideas, and now I want to create a real design.
Among other things, I had a global configuration object that every other function got something out of. Now, I must localize the object and pass pointers around. Thing is, mostly everyone needs this object. I've thought of three possible solutions:
a) Keep the configuration object
global (simplest, though not really a
solution)
b) Store pointers everywhere they are
needed (easy enough, though a waste
of memory, since some small
plain-old-data structures would need
it).
c) Create factories for the POD types
that need access to options, and have
the factory perform all operations on
them.
Of my ideas, only (c) sounds logical, but I don't want to needlessly complicate the structure. What would you guys do?
I'm fine with new ideas, and will provide whatever information about the program you want to know.
Thanks in advance!
I have to agree with #Carl Norum: there is nothing wrong with the global config setup you have now. You say that everybody "got something out of" it. As you know, the problem with globals comes when everybody writes into them. In your case, the config info truly is needed globally so deserves to be global.
If you want to make it be a little more decoupled and protected -- a little less global-ish -- then why not add some read/write access routines.
See, storing pointers everywhere isn't going to really solve the problem: it will only add a layer of indirection that will merely disguise or camouflage what are, in reality, the global accesses that are making you nervous. And that extra layer of indirection will add juuuuust enough room for juuuuust a teeny-weeny little bug to creep in.
So, bottom line: if stuff is naturally global then make it global and don't worry about the usual widespread received wisdom that's mostly correct but might not be the right thing in your application. To always be bound by the rules/propaganda that CS teachers put out there is, imo, the perfect example of a foolish consistency.
Global variables are awesome. Spend your time actually getting something done instead of refactoring for no reason. Every company I have worked at uses them heavily.
Ask yourself if you're actually gaining anything by moving it to an object you're just passing around everywhere. Might as well save yourself the extra complexity..
Go for B, unless profiling proves it to be a problem. On most machines, the memory required to store a pointer is very, very trivial.
i have read several answers on stackoverflow with this question in my mind, but my question is a little different.
what i want to know is for variables that are not dependent on other variables of the class, why can't i declare the variable public like we do in java and then access the variable directly?
i mean in objective c, if i have a variable which i have declared in the interface of a class, why can't i directly (without making its getters and setters) access with,
self.variable or instanceofclass.variable....?
this is what we usually do in java and other object oriented languages.
getters and setters have their own advantages, but when you are doing simple things,would it not be better if you access variables in the way i have mentioned above.
PS: i am very new to objective c, so if we can access the variables in the way that i am claiming we cannot , please excuse. i have tried doing so, but there was an error, hence i am asking, but it very well could have been due to something else. so again please excuse.
thank you in advance.
because it is fundamentally wrong. If you expose a member variable as public, you are exposing internal details of a storage strategy which is not supposed to be known to the client. This will make your life much harder if, in the future, you want to implement smart strategies like allocation on the fly, or even just putting a print statement every time the variable is accessed, for debug purposes. Accessing a public variable gives you much less freedom than calling a method, and you are bound to your choice because accessing a member var and calling a member function use different syntaxes, so you will have to go around and fix your code everywhere.
The only situation where this is not an issue is when you have a pure struct, a class whose members are purely to hold and carry around a bunch of data under a collective name, and the storage strategy is already exposed by the very nature of the bunch of data you are carrying around.
This may seem like a dumb topic, but I'm trying to learn some good coding practices.
I'm making a windows.forms application and I have reached a point where my partial Form class has 7 global variables (and their corresponding properties) declared and used - to name a few: one to determine if the app is registered, a Settings object that I need to access in many events, a Logger object, etc.
Is this bad coding? I mean, is it ok to declare a bunch of global variables and make use of them in the various event handlers/methods, or is there some better practice and I should rethink my code, to avoid having them?
I have a lot of work left to do in this application so it's in a first phase now, and with my coding style it looks like it will end up having even more than 20 global variables.
You might consider adding an App.config file and using this for your global settings (such as logger setup, etc). An advantage of this approach is that you can change these settings and restart the app without making code changes.
You can add key/value pairs in your App.config:
<appSettings>
<add key="YourKey" value="YourValue"/>
</appSettings>
and access them in code:
string yourValue = ConfigurationManager.AppSettings["YourKey"];
Performing the proper parsing (e.g. Int32.TryParse(..)) you can store data besides strings there.