Hacking Calling all Wii programmers, new coder needs some help.

cdoty

Well-Known Member
Member
Joined
Sep 14, 2009
Messages
329
Trophies
0
Website
www.rastersoft.net
XP
352
Country
United States
Yep that is what you want.

The u32 sector_size is the location where the value will be stored. The &sector_size passes the address of the variable to the function. If you don't pass the address any changes will be lost when the function returns. This is one way in which a function can return data. The others are by a return value (but, you're limited to one value), a pointer, or a pointer to a pointer. Pointers are typically only used for buffers. A pointer to a pointer is used if the function will allocate memory.
 

Foxi4

Endless Trash
Global Moderator
Joined
Sep 13, 2009
Messages
30,818
Trophies
3
Location
Gaming Grotto
XP
29,787
Country
Poland
Removing the *'s make it cause way more errors:
> "make"
template.c
c:/projects/wii/FreeSpace/source/template.c: In function 'main':
c:/projects/wii/FreeSpace/source/template.c:85:2: error: incompatible type for argument 1 of 'USBStorage_ReadCapacity'
c:/devkitPro/libogc/include/ogc/usbstorage.h:77:5: note: expected 'struct usbstorage_handle *' but argument is of type 'usbstorage_handle'
c:/projects/wii/FreeSpace/source/template.c:85:2: warning: passing argument 3 of 'USBStorage_ReadCapacity' makes pointer from integer without a cast [enabled by default]
c:/devkitPro/libogc/include/ogc/usbstorage.h:77:5: note: expected 'u32 *' but argument is of type 'u32'
c:/projects/wii/FreeSpace/source/template.c:85:2: warning: passing argument 4 of 'USBStorage_ReadCapacity' makes pointer from integer without a cast [enabled by default]
c:/devkitPro/libogc/include/ogc/usbstorage.h:77:5: note: expected 'u32 *' but argument is of type 'u32'
make[1]: *** [template.o] Error 1
"make": *** [build] Error 2

> Process Exit Code: 2
> Time Taken: 00:01
Analyze what the compiler is telling you, it's giving you accurate information on where you've made mistakes:

In line 77 and 85, you're using incorrect first, third and fourth arguments in the USBStorage_ReadCapacity function.

Compare the arguments you are using with the arguments required by the function:

s32 USBStorage_ReadCapacity(usbstorage_handle *dev, u8 lun, u32 *sector_size, u32 *n_sectors);

Joostin is putting you on the wrong track - the function expects pointers, arguments 1, 3 and 4 are pointers.

EDIT: Redacted due to new-found irrelevance, I was referring to "getting rid of * and &".
 
  • Like
Reactions: RiCK420

JoostinOnline

Certified Crash Test Dummy
Member
Joined
Apr 2, 2011
Messages
11,005
Trophies
1
Location
The Twilight Zone
Website
www.hacksden.com
XP
4,338
Country
United States
Analyze what the compiler is telling you, it's giving you accurate information on where you've made mistakes:

In line 77, you're using an incorrect first argument in the USBStorage_ReadCapacity. It's expecting a 32-bit pointer, but you're passing a 32-bit integer. Same with line 85.

Compare the arguments you are using with the arguments required by the functions:
s32 USBStorage_ReadCapacity(usbstorage_handle *dev, u8 lun, u32 *sector_size, u32 *n_sectors);
I was confused because I didn't realize what he had written. A look at the whole thing showed me what he was doing.

Joostin is putting you on the wrong track - the function expects pointers, arguments 1, 3 and 4 are pointers.
Actually, for that you need to use references, not pointers. What I wrote is correct.
 

RiCK420

Contributing Member
OP
Member
Joined
Oct 2, 2013
Messages
172
Trophies
0
XP
159
Country
United States
I don't know why it's not working. The warnings don't make sense. Anyway, I don't understand why you are jumping into something like this when you don't even know C or C++. You have to start out small. It doesn't matter that you know other languages.

All my projects are open source if you want to take a look. You can find the source at HacksDen.


The concept seemed simple enough, it only has 1 function/purpose, to retrieve space left on a disk.
Besides, it's a learning experience. :P
 

Foxi4

Endless Trash
Global Moderator
Joined
Sep 13, 2009
Messages
30,818
Trophies
3
Location
Gaming Grotto
XP
29,787
Country
Poland
I was confused because I didn't realize what he had written. A look at the whole thing showed me what he was doing.

Actually, for that you need to use references, not pointers. What I wrote is correct.

The function can expect a pointer if it's meant to use the data pointed at by the pointer, not the address of the data.

Useful literature: http://www.cplusplus.com/doc/tutorial/pointers/

EDIT: Edited for better clarity because at 2AM my technical lingo or knowledge isn't exactly spot-on.
 

JoostinOnline

Certified Crash Test Dummy
Member
Joined
Apr 2, 2011
Messages
11,005
Trophies
1
Location
The Twilight Zone
Website
www.hacksden.com
XP
4,338
Country
United States

Foxi4

Endless Trash
Global Moderator
Joined
Sep 13, 2009
Messages
30,818
Trophies
3
Location
Gaming Grotto
XP
29,787
Country
Poland
I've read that. Anyway, it works fine with references.
Fair enough. In any case...
& is the reference operator and can be read as "address of"
* is the dereference operator and can be read as "value pointed by"
Meaning when the function requires a particular address of something, you'll be using the reference operator "&" while when it requires the value pointed by a given pointer, you will be using "*".
 

RiCK420

Contributing Member
OP
Member
Joined
Oct 2, 2013
Messages
172
Trophies
0
XP
159
Country
United States
I've read that. Anyway, it works fine with references.

It doesn't give any data back or have any output though. Do I need to set it to a variable or an array?

something like:

data = USBStorage_ReadCapacity(&usb_device, lun, &sector_size, &num_of_sectors);
printf(data);

?

Or should USBStorage_ReadCapacity() already output something on it's own?
 

Foxi4

Endless Trash
Global Moderator
Joined
Sep 13, 2009
Messages
30,818
Trophies
3
Location
Gaming Grotto
XP
29,787
Country
Poland
It doesn't give any data back or have any output though. Do I need to set it to a variable or an array?

Or should USBStorage_ReadCapacity() already output something on it's own?

The function should at least return a 32-bit value which you should be able to print out - are you testing this on real hardware or on an emulator? It makes a huge difference.
 

RiCK420

Contributing Member
OP
Member
Joined
Oct 2, 2013
Messages
172
Trophies
0
XP
159
Country
United States
The function should at least return a 32-bit value which you should be able to print out - are you testing this on real hardware or on an emulator? It makes a huge difference.

I am testing it on real hardware, my real Wii.
 

JoostinOnline

Certified Crash Test Dummy
Member
Joined
Apr 2, 2011
Messages
11,005
Trophies
1
Location
The Twilight Zone
Website
www.hacksden.com
XP
4,338
Country
United States
It doesn't give any data back or have any output though. Do I need to set it to a variable or an array?

something like:

data = USBStorage_ReadCapacity(&usb_device, lun, &sector_size, &num_of_sectors);
printf(data);

?

Or should USBStorage_ReadCapacity() already output something on it's own?
You have to print it. This is why you need to start with the basics, you clearly don't understand them. To show the sector size, for example, you'd do this:
Code:
printf("Sector size is %u", sector_size);
 

Foxi4

Endless Trash
Global Moderator
Joined
Sep 13, 2009
Messages
30,818
Trophies
3
Location
Gaming Grotto
XP
29,787
Country
Poland
You have to print it. This is why you need to start with the basics, you clearly don't understand them. To show the sector size, for example, you'd do this:
Code:
printf("Sector size is %u", sector_size);
Oh? libogc's printf supports arguments like that? No fooling around with sprintf or converting to strings?

...libnds users are now jelly - you should know that. Our iprintf() is nothing like that (At least last time I checked)! :angry:
 

RiCK420

Contributing Member
OP
Member
Joined
Oct 2, 2013
Messages
172
Trophies
0
XP
159
Country
United States
You have to print it. This is why you need to start with the basics, you clearly don't understand them. To show the sector size, for example, you'd do this:
Code:
printf("Sector size is %u", sector_size);

Well I just asked if it needed to be printed out, so I at least had an idea of what needed to be done,
however the proper syntax I was unclear of. But thank you for the example.

What does %u mean? (it worked, but just want to know the meaning behind it, so I understand why it works as well.)

And thank you for your help. I have already learned quite a bit today, so it's not for nothing.
 

RiCK420

Contributing Member
OP
Member
Joined
Oct 2, 2013
Messages
172
Trophies
0
XP
159
Country
United States
from your example of:

printf("Sector size is %u", sector_size);

I was able to print number of sectors now as well:

printf("Number of sectors is %u", num_of_sectors);

So see, I am catching on. :P Thank you!
 

Foxi4

Endless Trash
Global Moderator
Joined
Sep 13, 2009
Messages
30,818
Trophies
3
Location
Gaming Grotto
XP
29,787
Country
Poland
%u is a format specifier used to display an argument, in this particular case it's going to be an unsigned number. The argument is specified outside of the quotation marks with are used as string deliminators. There are also %s for strings, %d for numbers, %f for floats and so on and so forth.

printf() function reference with format specifiers

After reading through the thread and the code (I smell copy-paste without much rhyme or reason - you don't seem to distinguish between declarations and used functions yet nor do you quite "get" types), I have to agree with Joostin in regards to your skill level versus expectations - you really need to start with the basics and learn at least a bit of C/C++ before you even start coding applications proper.

I mean, I'm not even a Wii coder and I saw quite a bit of faults in your original code which were fortunately quickly corrected by Joostin.
 
  • Like
Reactions: JoostinOnline

RiCK420

Contributing Member
OP
Member
Joined
Oct 2, 2013
Messages
172
Trophies
0
XP
159
Country
United States
I'm starting to understand them though:

& makes it not point to the data of the variable, but instead to the memory address where the variable is stored.

the * I'm a little less clear on, but it sounds like the * makes it read where the variable points to, also rather than its data.
 

RiCK420

Contributing Member
OP
Member
Joined
Oct 2, 2013
Messages
172
Trophies
0
XP
159
Country
United States
Everyone started off knowing nothing at one time. If I don't try, I'll never learn. And I do appreciate you guys being willing to coach me through it.
I am not just copy and pasting, I am learning from it as well. That is why I asked the question of what the %u meant, because I was not happy with just having it work, but also I wanted to understand WHY it worked, so I learn from it and can use it in the future.
 

JoostinOnline

Certified Crash Test Dummy
Member
Joined
Apr 2, 2011
Messages
11,005
Trophies
1
Location
The Twilight Zone
Website
www.hacksden.com
XP
4,338
Country
United States
Oh? libogc's printf supports arguments like that?
It's part of newlib, but yeah.
No fooling around with sprintf or converting to strings?

...libnds users are now jelly - you should know that. Our iprintf() is nothing like that (At least last time I checked)! :angry:
Yeah, I bought a flash cart thinking "It's going to be awesome writing NDS homebrew", then tried it out and hated it. I don't like doing extra work. :lol:

Everyone started off knowing nothing at one time. If I don't try, I'll never learn.
The difference being, we didn't jump right into the deep end (or maybe half way to the deep end). You need to learn to program properly.

Pointers and references are a pain in the ass, and I still make stupid mistakes with them sometimes (as I proved in this thread), but you need to learn basic syntax before you bother with them.
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • No one is chatting at the moment.
  • Sicklyboy @ Sicklyboy:
    maaaaan that's so awesome but I also don't want to fork over a hundo for it
  • Veho @ Veho:
    The fuuuuu---
  • Veho @ Veho:
    I thought it was an actual xBox at that price.
  • Sicklyboy @ Sicklyboy:
    I wanna grab a 360 Slim and a 360 E one of these days. Missed the boat of getting them at their lowest though, once they were discontinued. Could've got them for cheap back when I was a broke 20 something working at Target, but then again, I was a broke 20 something working at Target
  • Veho @ Veho:
    Being broke is no fun.
  • K3Nv2 @ K3Nv2:
    @Sicklyboy, $150 isn't that bad for a jtag slim on ebay
  • Veho @ Veho:
    I only wish it was actually playable.
  • Veho @ Veho:
    There's a guy on the Tube of You that makes playable mechanical arcade games out of Lego. This could work on the same principle.
  • Veho @ Veho:
    Just a couple of guys taking their manatee out for some fresh air, why you have to molest them?
  • Veho @ Veho:
    Stupid Chinese shop switched their shipping company and this one is slooooooow.
  • LeoTCK @ LeoTCK:
    STOP BUYING CHINESE CRAP THEN
  • LeoTCK @ LeoTCK:
    SUPPORT LOCAL PRODUCTS, MAKE REVOLUTION
  • LeoTCK @ LeoTCK:
    THEY KEEP REMOVING LOCAL SHIt AND REPLACING WItH INFERIOR CHINESE CRAP
  • LeoTCK @ LeoTCK:
    THATS WHY MY PARTNER CANT GET A GOOTWEAR HIS SIZE ANYMORE
  • LeoTCK @ LeoTCK:
    HE HAS BIG FOOT AND BIG DUCK
  • LeoTCK @ LeoTCK:
    d*ck i mean*
  • LeoTCK @ LeoTCK:
    lol
  • Veho @ Veho:
    Mkay.
  • Veho @ Veho:
    I just ordered another package from China just to spite you.
  • SylverReZ @ SylverReZ:
    Leo could not withstand communism.
  • SylverReZ @ SylverReZ:
    Its OUR products to begin with lol.
    SylverReZ @ SylverReZ: Its OUR products to begin with lol.