cpp:casting
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| cpp:casting [2026/04/24 12:22] – [const_cast<>] gthanos | cpp:casting [2026/04/24 12:28] (current) – [reinterpret_cast<>] gthanos | ||
|---|---|---|---|
| Line 190: | Line 190: | ||
| </ | </ | ||
| - | Συνοπτικός Πίνακας | + | **Συνοπτικός Πίνακας** |
| ^ Τύπος | ^ Τύπος | ||
| Line 206: | Line 206: | ||
| * **Ο Κίνδυνος: | * **Ο Κίνδυνος: | ||
| - | <code cpp> | + | < |
| void legacy_function(char* str) { | void legacy_function(char* str) { | ||
| /* ... */ | /* ... */ | ||
| Line 216: | Line 216: | ||
| </ | </ | ||
| + | ====== reinterpret_cast<> | ||
| + | Αυτός είναι ο πιο ισχυρός και επικίνδυνος τελεστής. Λέει στον compiler: " | ||
| + | |||
| + | **Τι κάνει: | ||
| + | |||
| + | **Προσοχή: | ||
| + | |||
| + | <code cpp reinterpret_cast.cpp> | ||
| + | long address = 0x7FFF1234; | ||
| + | // Ερμήνευσε αυτόν τον αριθμό ως διεύθυνση μνήμης ενός ακεραίου | ||
| + | int* p = reinterpret_cast< | ||
| + | </ | ||
| + | |||
| + | Ο συγκεκριμένος τελεστής μοιάζει με το type casting που γνωρίζουμε από τη γλώσσα C, διότι ο μεταγλωττιστής ακολουθεί χωρίς έλεγχο τις οδηγίες του προγραμματιστή. | ||
| - | void legacy_function(char* str) { /* ... */ } | ||
| - | const char* my_text = " | ||
| - | // legacy_function(my_text); | ||
| - | legacy_function(const_cast< | ||
| - | ====== reinterpret_cast<> | ||
cpp/casting.1777033357.txt.gz · Last modified: 2026/04/24 12:22 by gthanos
