Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Poll

What programming topic would you want the next challenge to be about?  (It might be a good opportunity to focus on a subject you're not familiar with or to reinforce knowledge on one that you already know)

Control Flow
- 2 (2.2%)
Arrays, Strings, Pointers, and References
- 8 (9%)
Functions
- 4 (4.5%)
Basic object-oriented programming
- 30 (33.7%)
A bit more advanced OOP (Composition, Operator overloading, Inheritance, Virtual Functions)
- 18 (20.2%)
Templates
- 8 (9%)
Other (Explain)
- 4 (4.5%)
Working with files?  (Streams)
- 15 (16.9%)

Total Members Voted: 89


Pages: 1 ... 11 12 [13] 14 15 ... 78

Author Topic: Programming Challenges & Resources (#bay12prog) Initiative  (Read 95771 times)

Blacken

  • Bay Watcher
  • Orange Polar Bear
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #180 on: June 28, 2010, 07:59:21 pm »

Char is C++'s byte.
The C# "byte" construct is analogous to a unsigned char. C#'s "char" is analogous to a signed char.

It is often possible to use one or the other for algorithmic purposes, but it breaks your type system.
Logged
"There's vermin fish, which fisherdwarves catch, and animal fish, which catch fisherdwarves." - Flame11235

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #181 on: June 29, 2010, 01:45:04 pm »

Ok, now I'm confused. Earlier here it was determined that structs and classes in C++ are not guaranteed to behave like continuous arrays in memory.

The OpenGL wiki however uses this example:

Code: [Select]
struct MyVertex
{
float x, y, z;        //Vertex
float nx, ny, nz;     //Normal
float s0, t0;         //Texcoord0
float s1, t1;         //Texcoord1
float s2, t2;         //Texcoord2
float padding[4];
};
MyVertex pvertices[XXX];
And the pvertices array is subsequently used as an array of floats.

Does this mean that "not guaranteed to be contiguous" can be translated as "only on really obscure systems"? For instance, a char is not always 8 bits on every system, but it will be on any common server or PC that might run my program, so that assumption is a safe one to make.
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

Blacken

  • Bay Watcher
  • Orange Polar Bear
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #182 on: June 29, 2010, 01:56:37 pm »

As far as I know, structures will always be contiguous in memory. They may be tightly packed or data members may be aligned on a specific boundary (usually 32 bits, even in 64-bit architectures). In either case, they will be a contiguous block of memory (just indirecting inside with pointers may be implementation-dependent).

There may be systems that do not operate this way, but I am fairly sure they are not standard C++.
Logged
"There's vermin fish, which fisherdwarves catch, and animal fish, which catch fisherdwarves." - Flame11235

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #183 on: June 29, 2010, 04:58:25 pm »

As far as I know, structures will always be contiguous in memory. They may be tightly packed or data members may be aligned on a specific boundary (usually 32 bits, even in 64-bit architectures). In either case, they will be a contiguous block of memory (just indirecting inside with pointers may be implementation-dependent).

There may be systems that do not operate this way, but I am fairly sure they are not standard C++.
Not according to cert: https://www.securecoding.cert.org/confluence/display/seccode/ARR37-C.+Do+not+add+or+subtract+an+integer+to+a+pointer+to+a+non-array+object, and DrPizza.
And doing pointer arithmetic is probably what the OGL function is going to do with that data.

I'll just take my chances, working with vertex structs and pixel-objects is too good to pass, and if it fails I can always make is slower.
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

Blacken

  • Bay Watcher
  • Orange Polar Bear
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #184 on: June 29, 2010, 05:32:24 pm »

It seems that you're conflating struct contiguousness (as in, a struct "is" this block of memory) and struct packing. Structs are contiguous; sizeof() accounts for the entire size of the struct including padding and no library memory allocation routine will allocate data types into the padding areas. Pointer arithmetic into a struct is preposterously unwise because that padding can vary (I've only ever seen it aligned on 4-byte boundaries, as I said, but apparently the spec doesn't cover the issue).

That there is padding inside the struct does not make it noncontiguous. It's still unwise to screw around with them though: the speed hit from using the actual struct offsets via the -> or . operators is so utterly marginal as to not even be on a profiler's radar.
Logged
"There's vermin fish, which fisherdwarves catch, and animal fish, which catch fisherdwarves." - Flame11235

qwertyuiopas

  • Bay Watcher
  • Photoshop is for elves who cannot use MSPaint.
    • View Profile
    • uristqwerty.ca, my current (barren) site.
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #185 on: June 29, 2010, 08:22:02 pm »

If a struct only contains one type, it will, from my understanding, be like an array for memory placement. If you mix types, however, even slightly, you cannot guarentee it, unless you know what you are doing. So, most areas that they do will probably design the struct to be as compatible as possible, so that it should remain the same everywhere it is compiled...
Logged
Eh?
Eh!

Blacken

  • Bay Watcher
  • Orange Polar Bear
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #186 on: June 29, 2010, 09:29:02 pm »

If a struct only contains one type, it will, from my understanding, be like an array for memory placement.
While I know from personal experience that this is generally true, I don't think that it must be true as per spec. I could be wrong, though.
Logged
"There's vermin fish, which fisherdwarves catch, and animal fish, which catch fisherdwarves." - Flame11235

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #187 on: June 30, 2010, 02:57:43 am »

Yeah, and if I make sure I pad it myself to a number of bytes with a power of 2, it should work...

Hell, if even the OpenGL Wiki does it...
This works really well with generating textures. Being able to use "pixel" classes, which I can add, subtract and multiply (doing nifty shizzle with alpha's and colors), and use it directly as a source bitmap would be great.

I'll let you know how it turned out (if it ever does).
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

LoopyDood

  • Bay Watcher
  • Reinventing the Wheel
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #188 on: July 02, 2010, 03:36:11 pm »

I'm an aspiring programmer, and I'm either going to college this September or next for a computer engineering course. I have taken classes in programming, which used Java to teach, but they sucked. We usually let Netbeans set everything up, made GUIs with Netbeans' drag and drop GUI creator, and did not learn much about object oriented programming concepts. Thanks to that I don't have a clear understanding of the fundamentals of Java or object oriented programming at all. I am looking for a book that will teach me programming fundamentals using Java, but I'm having a hard time deciding what to buy. I also want to keep the price at around $30 or below on Amazon. I am not a programmer trying to learn Java specifically, rather a person trying to learn to program using Java.

Can anyone give me recommendations?

eerr

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #189 on: July 02, 2010, 04:12:14 pm »

What exactly did you do to learn?
Logged

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #190 on: July 02, 2010, 04:49:52 pm »

In case anyone wants to try it, I've found a very good book on LISP: http://www.gigamonkeys.com/book/. Printed versions can be pretty pricey, but the web version's free.
Logged

LoopyDood

  • Bay Watcher
  • Reinventing the Wheel
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #191 on: July 02, 2010, 05:12:42 pm »

We started out with Netbeans, a Java IDE that does everything for you, which was the first mistake. The first program I made displayed Hello World in a label when you clicked a button. All I had to do was drag and drop the button and label in place, then edit the method to make the button work. The programs were pretty much all like that for the rest of the course, drag and dropping a GUI in then editing single methods for each button. It didn't teach me OOP concepts or the fundamentals of Java at all.

eerr

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #192 on: July 02, 2010, 05:35:55 pm »


You have objects that perform operations near themselves, and call methods on other object to accomplish the overal task.

Are you saying you didn't make more than a single class in java?

Just tell me what your final project was.
« Last Edit: July 02, 2010, 05:37:39 pm by eerr »
Logged

LoopyDood

  • Bay Watcher
  • Reinventing the Wheel
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #193 on: July 02, 2010, 05:53:35 pm »

We made a 20-tile concentration game. I scored a 48/50 on it.

Like I said, I'm just looking for a book to learn from. Do you have any suggestions?

eerr

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #194 on: July 02, 2010, 08:07:24 pm »

Eclipse auto-embeds documentation that can be looked up online, but is otherwise a hassle to lookup.

"extremely" convenient.


Logged
Pages: 1 ... 11 12 [13] 14 15 ... 78